Skip to content

Commit

Permalink
fix sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
alicejli committed Jan 23, 2024
1 parent 3a5518a commit 2c7ea7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1316,15 +1316,15 @@ static List<Statement> createRequestMutatorBody(
VariableExpr returnBuilderVarExpr) {

if (method.inputType().reference() == null
|| method.inputType().reference().fullName() == null){
|| method.inputType().reference().fullName() == null) {
return bodyStatements;
}
String methodRequestName = method.inputType().reference().fullName();
if(Strings.isNullOrEmpty(methodRequestName)){
if (Strings.isNullOrEmpty(methodRequestName)) {
return bodyStatements;
}
Message methodRequestMessage = messageTypes.get(methodRequestName);
if(methodRequestMessage == null || methodRequestMessage.fields() == null){
if (methodRequestMessage == null || methodRequestMessage.fields() == null) {
return bodyStatements;
}
for (String field : method.autoPopulatedFields()) {
Expand Down Expand Up @@ -1422,10 +1422,21 @@ static Boolean shouldAutoPopulateFields(
Method method, ImmutableMap<String, Message> messageTypes) {

boolean shouldAutoPopulate = false;

if (method.inputType().reference() == null
|| method.inputType().reference().fullName() == null) {
return shouldAutoPopulate;
}
String methodRequestName = method.inputType().reference().fullName();
if (Strings.isNullOrEmpty(methodRequestName)) {
return shouldAutoPopulate;
}
Message methodRequestMessage = messageTypes.get(methodRequestName);
if (methodRequestMessage == null || methodRequestMessage.fields() == null) {
return shouldAutoPopulate;
}
for (String field : method.autoPopulatedFields()) {
Optional<Field> matchingField =
messageTypes.get(method.inputType().reference().fullName()).fields().stream()
methodRequestMessage.fields().stream()
.filter(field1 -> field1.name().equals(field))
.findFirst();
if (!matchingField.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HttpJsonDirectCallable<RequestT, ResponseT> extends UnaryCallable<RequestT
private final ApiMethodDescriptor<RequestT, ResponseT> descriptor;
private final TypeRegistry typeRegistry;

private HttpJsonCallSettings httpJsonCallSettings;
private final HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings;

HttpJsonDirectCallable(ApiMethodDescriptor<RequestT, ResponseT> descriptor) {
this(descriptor, null, null);
Expand All @@ -53,13 +53,13 @@ class HttpJsonDirectCallable<RequestT, ResponseT> extends UnaryCallable<RequestT
HttpJsonDirectCallable(
ApiMethodDescriptor<RequestT, ResponseT> descriptor,
TypeRegistry typeRegistry,
HttpJsonCallSettings httpJsonCallSettings) {
HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings) {
this.descriptor = descriptor;
this.typeRegistry = typeRegistry;
this.httpJsonCallSettings = httpJsonCallSettings;
}

public HttpJsonDirectCallable(HttpJsonCallSettings httpJsonCallSettings) {
public HttpJsonDirectCallable(HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings) {
this.descriptor = Preconditions.checkNotNull(httpJsonCallSettings.getMethodDescriptor());
this.httpJsonCallSettings = httpJsonCallSettings;
this.typeRegistry = Preconditions.checkNotNull(httpJsonCallSettings.getTypeRegistry());
Expand All @@ -77,7 +77,7 @@ public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext inputCon
RequestT newRequest = request;

if (httpJsonCallSettings != null && httpJsonCallSettings.getRequestMutator() != null) {
newRequest = (RequestT) httpJsonCallSettings.getRequestMutator().apply(request);
newRequest = httpJsonCallSettings.getRequestMutator().apply(request);
}

HttpJsonClientCall<RequestT, ResponseT> clientCall =
Expand Down

0 comments on commit 2c7ea7e

Please sign in to comment.