Skip to content

Commit

Permalink
chore: add @CanIgnoreReturnValue to builder set methods
Browse files Browse the repository at this point in the history
Preparation for enabling errorprone
  • Loading branch information
Noam Lewis committed Nov 7, 2023
1 parent 47d9a6e commit 7e6e937
Show file tree
Hide file tree
Showing 27 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Collection;
Expand Down Expand Up @@ -154,11 +155,13 @@ protected Builder(AppEngineCredentials credentials) {
this.appIdentityService = credentials.appIdentityService;
}

@CanIgnoreReturnValue
public Builder setScopes(Collection<String> scopes) {
this.scopes = scopes;
return this;
}

@CanIgnoreReturnValue
public Builder setAppIdentityService(AppIdentityService appIdentityService) {
this.appIdentityService = appIdentityService;
return this;
Expand Down
5 changes: 5 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/AccessToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package com.google.auth.oauth2;

import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -158,18 +159,21 @@ public Date getExpirationTime() {
return this.expirationTime;
}

@CanIgnoreReturnValue
public Builder setTokenValue(String tokenValue) {
this.tokenValue = tokenValue;
return this;
}

@CanIgnoreReturnValue
public Builder setScopes(String scopes) {
if (scopes != null && scopes.trim().length() > 0) {
this.scopes = Arrays.asList(scopes.split(" "));
}
return this;
}

@CanIgnoreReturnValue
public Builder setScopes(List<String> scopes) {
if (scopes == null) {
this.scopes = new ArrayList<>();
Expand All @@ -180,6 +184,7 @@ public Builder setScopes(List<String> scopes) {
return this;
}

@CanIgnoreReturnValue
public Builder setExpirationTime(Date expirationTime) {
this.expirationTime = expirationTime;
return this;
Expand Down
10 changes: 10 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/AwsRequestSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package com.google.auth.oauth2;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -130,46 +131,55 @@ static class Builder {
private String region;
private String authorizationHeader;

@CanIgnoreReturnValue
Builder setSignature(String signature) {
this.signature = signature;
return this;
}

@CanIgnoreReturnValue
Builder setCredentialScope(String credentialScope) {
this.credentialScope = credentialScope;
return this;
}

@CanIgnoreReturnValue
Builder setSecurityCredentials(AwsSecurityCredentials awsSecurityCredentials) {
this.awsSecurityCredentials = awsSecurityCredentials;
return this;
}

@CanIgnoreReturnValue
Builder setUrl(String url) {
this.url = url;
return this;
}

@CanIgnoreReturnValue
Builder setHttpMethod(String httpMethod) {
this.httpMethod = httpMethod;
return this;
}

@CanIgnoreReturnValue
Builder setCanonicalHeaders(Map<String, String> canonicalHeaders) {
this.canonicalHeaders = new HashMap<>(canonicalHeaders);
return this;
}

@CanIgnoreReturnValue
Builder setDate(String date) {
this.date = date;
return this;
}

@CanIgnoreReturnValue
Builder setRegion(String region) {
this.region = region;
return this;
}

@CanIgnoreReturnValue
Builder setAuthorizationHeader(String authorizationHeader) {
this.authorizationHeader = authorizationHeader;
return this;
Expand Down
3 changes: 3 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/AwsRequestSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.io.BaseEncoding;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.net.URI;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
Expand Down Expand Up @@ -298,11 +299,13 @@ private Builder(
this.region = region;
}

@CanIgnoreReturnValue
Builder setRequestPayload(String requestPayload) {
this.requestPayload = requestPayload;
return this;
}

@CanIgnoreReturnValue
Builder setAdditionalHeaders(Map<String, String> additionalHeaders) {
if (additionalHeaders.containsKey("date") && additionalHeaders.containsKey("x-amz-date")) {
throw new IllegalArgumentException("One of {date, x-amz-date} can be specified, not both.");
Expand Down
3 changes: 3 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/ClientId.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.util.Preconditions;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -184,11 +185,13 @@ protected Builder(ClientId clientId) {
this.clientSecret = clientId.getClientSecret();
}

@CanIgnoreReturnValue
public Builder setClientId(String clientId) {
this.clientId = clientId;
return this;
}

@CanIgnoreReturnValue
public Builder setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.api.client.json.JsonParser;
import com.google.common.base.Charsets;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -131,6 +132,7 @@ protected Builder(CloudShellCredentials credentials) {
this.authPort = credentials.authPort;
}

@CanIgnoreReturnValue
public Builder setAuthPort(int authPort) {
this.authPort = authPort;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.google.common.base.Joiner;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -549,11 +550,13 @@ protected Builder(ComputeEngineCredentials credentials) {
this.scopes = credentials.scopes;
}

@CanIgnoreReturnValue
public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
this.transportFactory = transportFactory;
return this;
}

@CanIgnoreReturnValue
public Builder setScopes(Collection<String> scopes) {
this.scopes = scopes;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.client.json.GenericJson;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -124,11 +125,13 @@ private Builder() {}
* @param rule the collection of rules to be set, should not be null
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setRules(List<AccessBoundaryRule> rule) {
accessBoundaryRules = new ArrayList<>(checkNotNull(rule));
return this;
}

@CanIgnoreReturnValue
public CredentialAccessBoundary.Builder addRule(AccessBoundaryRule rule) {
if (accessBoundaryRules == null) {
accessBoundaryRules = new ArrayList<>();
Expand Down Expand Up @@ -218,6 +221,7 @@ private Builder() {}
* @param availableResource the resource name to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setAvailableResource(String availableResource) {
this.availableResource = availableResource;
return this;
Expand All @@ -232,6 +236,7 @@ public Builder setAvailableResource(String availableResource) {
* @param availablePermissions the collection of permissions to set, should not be null
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setAvailablePermissions(List<String> availablePermissions) {
this.availablePermissions = new ArrayList<>(checkNotNull(availablePermissions));
return this;
Expand Down Expand Up @@ -261,6 +266,7 @@ public Builder addAvailablePermission(String availablePermission) {
* @param availabilityCondition the {@code AvailabilityCondition} to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setAvailabilityCondition(AvailabilityCondition availabilityCondition) {
this.availabilityCondition = availabilityCondition;
return this;
Expand Down Expand Up @@ -337,6 +343,7 @@ private Builder() {}
* @param expression the expression to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setExpression(String expression) {
this.expression = expression;
return this;
Expand All @@ -348,6 +355,7 @@ public Builder setExpression(String expression) {
* @param title the title to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setTitle(String title) {
this.title = title;
return this;
Expand All @@ -359,6 +367,7 @@ public Builder setTitle(String title) {
* @param description the description to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setDescription(String description) {
this.description = description;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import com.google.auth.http.HttpTransportFactory;
import com.google.common.annotations.VisibleForTesting;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.IOException;

/**
Expand Down Expand Up @@ -166,16 +167,19 @@ public static class Builder extends OAuth2Credentials.Builder {

private Builder() {}

@CanIgnoreReturnValue
public Builder setSourceCredential(GoogleCredentials sourceCredential) {
this.sourceCredential = sourceCredential;
return this;
}

@CanIgnoreReturnValue
public Builder setCredentialAccessBoundary(CredentialAccessBoundary credentialAccessBoundary) {
this.credentialAccessBoundary = credentialAccessBoundary;
return this;
}

@CanIgnoreReturnValue
public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
this.transportFactory = transportFactory;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.google.auth.http.HttpTransportFactory;
import com.google.common.base.MoreObjects;
import com.google.common.io.BaseEncoding;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
Expand Down Expand Up @@ -401,6 +402,7 @@ protected Builder(ExternalAccountAuthorizedUserCredentials credentials) {
* @param transportFactory the {@code HttpTransportFactory} to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
this.transportFactory = transportFactory;
return this;
Expand All @@ -413,6 +415,7 @@ public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
* @param audience the audience to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setAudience(String audience) {
this.audience = audience;
return this;
Expand All @@ -424,6 +427,7 @@ public Builder setAudience(String audience) {
* @param tokenUrl the token exchange url to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setTokenUrl(String tokenUrl) {
this.tokenUrl = tokenUrl;
return this;
Expand All @@ -435,6 +439,7 @@ public Builder setTokenUrl(String tokenUrl) {
* @param tokenInfoUrl the token info url to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setTokenInfoUrl(String tokenInfoUrl) {
this.tokenInfoUrl = tokenInfoUrl;
return this;
Expand All @@ -446,6 +451,7 @@ public Builder setTokenInfoUrl(String tokenInfoUrl) {
* @param revokeUrl the revoke url to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setRevokeUrl(String revokeUrl) {
this.revokeUrl = revokeUrl;
return this;
Expand All @@ -457,6 +463,7 @@ public Builder setRevokeUrl(String revokeUrl) {
* @param refreshToken the refresh token
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
return this;
Expand All @@ -468,6 +475,7 @@ public Builder setRefreshToken(String refreshToken) {
* @param clientId the client ID
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setClientId(String clientId) {
this.clientId = clientId;
return this;
Expand All @@ -479,6 +487,7 @@ public Builder setClientId(String clientId) {
* @param clientSecret the client secret
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
return this;
Expand All @@ -490,6 +499,7 @@ public Builder setClientSecret(String clientSecret) {
* @param quotaProjectId the quota and billing project id to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setQuotaProjectId(String quotaProjectId) {
super.setQuotaProjectId(quotaProjectId);
return this;
Expand All @@ -501,6 +511,7 @@ public Builder setQuotaProjectId(String quotaProjectId) {
* @param accessToken the access token
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setAccessToken(AccessToken accessToken) {
super.setAccessToken(accessToken);
return this;
Expand Down
Loading

0 comments on commit 7e6e937

Please sign in to comment.