From a127993dc1a169bf9039bbbcd655c9d6ef608250 Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Fri, 10 Sep 2021 17:55:52 -0400 Subject: [PATCH 1/4] Remove warnings --- .../generator/engine/ast/AnnotationNode.java | 2 +- .../engine/ast/ArithmeticOperationExpr.java | 2 + .../engine/ast/AssignmentOperationExpr.java | 1 + .../generator/engine/ast/BlockComment.java | 1 + .../engine/ast/ConcreteReference.java | 12 +-- .../api/generator/engine/ast/EnumRefExpr.java | 1 + .../google/api/generator/engine/ast/Expr.java | 1 + .../engine/ast/LogicalOperationExpr.java | 1 + .../engine/ast/MethodDefinition.java | 6 +- .../generator/engine/ast/NewObjectExpr.java | 1 + .../api/generator/engine/ast/ObjectValue.java | 2 + .../generator/engine/ast/OperationExpr.java | 2 + .../api/generator/engine/ast/Reference.java | 1 + .../engine/ast/ReferenceConstructorExpr.java | 3 +- .../engine/ast/RelationalOperationExpr.java | 1 + .../api/generator/engine/ast/Statement.java | 1 + .../engine/ast/StringObjectValue.java | 1 + .../api/generator/engine/ast/TypeNode.java | 22 +---- .../engine/ast/UnaryOperationExpr.java | 3 + .../engine/writer/ImportWriterVisitor.java | 6 +- .../engine/writer/JavaWriterVisitor.java | 5 +- .../comment/ServiceClientCommentComposer.java | 1 - .../comment/SettingsCommentComposer.java | 1 - ...ctServiceCallableFactoryClassComposer.java | 20 ++-- .../AbstractServiceClientClassComposer.java | 77 ++++++++------- ...bstractServiceClientTestClassComposer.java | 86 ++++------------- .../AbstractServiceSettingsClassComposer.java | 17 ++-- .../AbstractServiceStubClassComposer.java | 20 ++-- ...tractServiceStubSettingsClassComposer.java | 65 +++++++++---- ...ractTransportServiceStubClassComposer.java | 78 +++++++++------ .../common/BatchingDescriptorComposer.java | 14 +-- .../common/RetrySettingsComposer.java | 5 +- .../defaultvalue/DefaultValueComposer.java | 9 +- ...pcServiceCallableFactoryClassComposer.java | 33 +++++-- .../grpc/GrpcServiceStubClassComposer.java | 5 +- .../grpc/MockServiceClassComposer.java | 2 +- .../grpc/MockServiceImplClassComposer.java | 14 ++- .../grpc/ServiceClientTestClassComposer.java | 13 ++- .../ServiceStubSettingsClassComposer.java | 2 +- .../ResourceNameHelperClassComposer.java | 95 ++++++++++++------- .../HttpJsonServiceStubClassComposer.java | 1 + .../rest/ServiceClientTestClassComposer.java | 12 ++- .../gapic/composer/store/TypeStore.java | 13 ++- .../protoparser/MethodSignatureParser.java | 25 ++--- .../gapic/protoparser/TypeParser.java | 5 - .../com/google/api/generator/util/Trie.java | 23 +++-- 46 files changed, 385 insertions(+), 326 deletions(-) diff --git a/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java b/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java index 888262cbf4..1a3412aa6c 100644 --- a/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java +++ b/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java @@ -25,7 +25,7 @@ public abstract class AnnotationNode implements AstNode { public static AnnotationNode DEPRECATED = AnnotationNode.builder().setType(annotationType(Deprecated.class)).build(); - private static TypeNode annotationType(Class clazz) { + private static TypeNode annotationType(Class clazz) { return TypeNode.withReference(ConcreteReference.withClazz(clazz)); } diff --git a/src/main/java/com/google/api/generator/engine/ast/ArithmeticOperationExpr.java b/src/main/java/com/google/api/generator/engine/ast/ArithmeticOperationExpr.java index 1a362758fd..886ec56ad4 100644 --- a/src/main/java/com/google/api/generator/engine/ast/ArithmeticOperationExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/ArithmeticOperationExpr.java @@ -24,8 +24,10 @@ public abstract class ArithmeticOperationExpr implements OperationExpr { public abstract Expr rhsExpr(); + @Override public abstract OperatorKind operatorKind(); + @Override public abstract TypeNode type(); @Override diff --git a/src/main/java/com/google/api/generator/engine/ast/AssignmentOperationExpr.java b/src/main/java/com/google/api/generator/engine/ast/AssignmentOperationExpr.java index af73f0b44f..4c2cfeec2e 100644 --- a/src/main/java/com/google/api/generator/engine/ast/AssignmentOperationExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/AssignmentOperationExpr.java @@ -23,6 +23,7 @@ public abstract class AssignmentOperationExpr implements OperationExpr { public abstract Expr valueExpr(); + @Override public abstract OperatorKind operatorKind(); @Override diff --git a/src/main/java/com/google/api/generator/engine/ast/BlockComment.java b/src/main/java/com/google/api/generator/engine/ast/BlockComment.java index 00f98aa2ec..9a9bc0d0cc 100644 --- a/src/main/java/com/google/api/generator/engine/ast/BlockComment.java +++ b/src/main/java/com/google/api/generator/engine/ast/BlockComment.java @@ -18,6 +18,7 @@ @AutoValue public abstract class BlockComment implements Comment { + @Override public abstract String comment(); @Override diff --git a/src/main/java/com/google/api/generator/engine/ast/ConcreteReference.java b/src/main/java/com/google/api/generator/engine/ast/ConcreteReference.java index 144c4beca1..5af0dbe869 100644 --- a/src/main/java/com/google/api/generator/engine/ast/ConcreteReference.java +++ b/src/main/java/com/google/api/generator/engine/ast/ConcreteReference.java @@ -32,10 +32,10 @@ public abstract class ConcreteReference implements Reference { private static final String RIGHT_ANGLE = ">"; private static final String QUESTION_MARK = "?"; - private static final Class WILDCARD_CLAZZ = ReferenceWildcard.class; + private static final Class WILDCARD_CLAZZ = ReferenceWildcard.class; // Private. - abstract Class clazz(); + abstract Class clazz(); @Override public void accept(AstNodeVisitor visitor) { @@ -105,7 +105,7 @@ public ImmutableList enclosingClassNames() { } // The innermost type will be the last element in the list. ImmutableList.Builder listBuilder = new ImmutableList.Builder<>(); - Class currentClz = clazz(); + Class currentClz = clazz(); while (currentClz.getEnclosingClass() != null) { listBuilder.add(currentClz.getEnclosingClass().getSimpleName()); currentClz = currentClz.getEnclosingClass(); @@ -198,7 +198,7 @@ public Reference copyAndSetGenerics(List generics) { return toBuilder().setGenerics(generics).build(); } - public static ConcreteReference withClazz(Class clazz) { + public static ConcreteReference withClazz(Class clazz) { return builder().setClazz(clazz).build(); } @@ -222,7 +222,7 @@ public static Builder builder() { @AutoValue.Builder public abstract static class Builder { - public abstract Builder setClazz(Class clazz); + public abstract Builder setClazz(Class clazz); public abstract Builder setUseFullName(boolean useFullName); @@ -239,7 +239,7 @@ public Builder setGenerics(Reference... references) { public abstract ConcreteReference autoBuild(); // Private. - abstract Class clazz(); + abstract Class clazz(); abstract ImmutableList generics(); diff --git a/src/main/java/com/google/api/generator/engine/ast/EnumRefExpr.java b/src/main/java/com/google/api/generator/engine/ast/EnumRefExpr.java index 9c2c49e756..8dcf18679b 100644 --- a/src/main/java/com/google/api/generator/engine/ast/EnumRefExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/EnumRefExpr.java @@ -21,6 +21,7 @@ public abstract class EnumRefExpr implements Expr { public abstract IdentifierNode identifier(); + @Override public abstract TypeNode type(); @Override diff --git a/src/main/java/com/google/api/generator/engine/ast/Expr.java b/src/main/java/com/google/api/generator/engine/ast/Expr.java index 6adc7a4fa5..134d2464d8 100644 --- a/src/main/java/com/google/api/generator/engine/ast/Expr.java +++ b/src/main/java/com/google/api/generator/engine/ast/Expr.java @@ -17,5 +17,6 @@ public interface Expr extends AstNode { TypeNode type(); + @Override void accept(AstNodeVisitor visitor); } diff --git a/src/main/java/com/google/api/generator/engine/ast/LogicalOperationExpr.java b/src/main/java/com/google/api/generator/engine/ast/LogicalOperationExpr.java index 2387345d31..9210ec3593 100644 --- a/src/main/java/com/google/api/generator/engine/ast/LogicalOperationExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/LogicalOperationExpr.java @@ -24,6 +24,7 @@ public abstract class LogicalOperationExpr implements OperationExpr { public abstract Expr rhsExpr(); + @Override public abstract OperatorKind operatorKind(); @Override diff --git a/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java b/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java index 3067dfc49a..643e600e6d 100644 --- a/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java +++ b/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java @@ -244,11 +244,11 @@ public MethodDefinition build() { "Abstract methods cannot be static, final, or private"); } - // If this method overrides another, ensure that the Override annotaiton is the last one. + // If this method overrides another, ensure that the Override annotation is the last one. ImmutableList processedAnnotations = annotations(); if (isOverride()) { processedAnnotations = - annotations() + ImmutableList .builder() .addAll(annotations()) .add(AnnotationNode.OVERRIDE) @@ -256,7 +256,7 @@ public MethodDefinition build() { } // Remove duplicates while maintaining insertion order. setAnnotations( - new LinkedHashSet(processedAnnotations) + new LinkedHashSet<>(processedAnnotations) .stream().collect(Collectors.toList())); MethodDefinition method = autoBuild(); diff --git a/src/main/java/com/google/api/generator/engine/ast/NewObjectExpr.java b/src/main/java/com/google/api/generator/engine/ast/NewObjectExpr.java index 50fbbed983..bbba011dff 100644 --- a/src/main/java/com/google/api/generator/engine/ast/NewObjectExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/NewObjectExpr.java @@ -23,6 +23,7 @@ @AutoValue public abstract class NewObjectExpr implements Expr { + @Override public abstract TypeNode type(); public abstract ImmutableList arguments(); diff --git a/src/main/java/com/google/api/generator/engine/ast/ObjectValue.java b/src/main/java/com/google/api/generator/engine/ast/ObjectValue.java index 49dd6abd9e..3cde72c4e9 100644 --- a/src/main/java/com/google/api/generator/engine/ast/ObjectValue.java +++ b/src/main/java/com/google/api/generator/engine/ast/ObjectValue.java @@ -15,7 +15,9 @@ package com.google.api.generator.engine.ast; public interface ObjectValue extends Value { + @Override TypeNode type(); + @Override String value(); } diff --git a/src/main/java/com/google/api/generator/engine/ast/OperationExpr.java b/src/main/java/com/google/api/generator/engine/ast/OperationExpr.java index 924a6a6930..36473e6e97 100644 --- a/src/main/java/com/google/api/generator/engine/ast/OperationExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/OperationExpr.java @@ -18,7 +18,9 @@ public interface OperationExpr extends Expr { OperatorKind operatorKind(); + @Override TypeNode type(); + @Override void accept(AstNodeVisitor visitor); } diff --git a/src/main/java/com/google/api/generator/engine/ast/Reference.java b/src/main/java/com/google/api/generator/engine/ast/Reference.java index fdc2c5c5ee..4dce11783f 100644 --- a/src/main/java/com/google/api/generator/engine/ast/Reference.java +++ b/src/main/java/com/google/api/generator/engine/ast/Reference.java @@ -19,6 +19,7 @@ import javax.annotation.Nullable; public interface Reference extends AstNode { + @Override void accept(AstNodeVisitor visitor); ImmutableList generics(); diff --git a/src/main/java/com/google/api/generator/engine/ast/ReferenceConstructorExpr.java b/src/main/java/com/google/api/generator/engine/ast/ReferenceConstructorExpr.java index 25940b0d3d..b68ff61ded 100644 --- a/src/main/java/com/google/api/generator/engine/ast/ReferenceConstructorExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/ReferenceConstructorExpr.java @@ -28,6 +28,7 @@ public enum KeywordKind { SUPER } + @Override public abstract TypeNode type(); public abstract KeywordKind keywordKind(); @@ -73,7 +74,7 @@ public Builder setArguments(Expr... arguments) { public ReferenceConstructorExpr build() { ReferenceConstructorExpr referenceConstructorExpr = autoBuild(); Preconditions.checkState( - referenceConstructorExpr.type().isReferenceType(referenceConstructorExpr.type()), + TypeNode.isReferenceType(referenceConstructorExpr.type()), "A this/super constructor must have a reference type."); NodeValidator.checkNoNullElements( diff --git a/src/main/java/com/google/api/generator/engine/ast/RelationalOperationExpr.java b/src/main/java/com/google/api/generator/engine/ast/RelationalOperationExpr.java index 80f0e4711b..d143abad5e 100644 --- a/src/main/java/com/google/api/generator/engine/ast/RelationalOperationExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/RelationalOperationExpr.java @@ -23,6 +23,7 @@ public abstract class RelationalOperationExpr implements OperationExpr { public abstract Expr rhsExpr(); + @Override public abstract OperatorKind operatorKind(); @Override diff --git a/src/main/java/com/google/api/generator/engine/ast/Statement.java b/src/main/java/com/google/api/generator/engine/ast/Statement.java index 041d5bfd0f..954b279fd7 100644 --- a/src/main/java/com/google/api/generator/engine/ast/Statement.java +++ b/src/main/java/com/google/api/generator/engine/ast/Statement.java @@ -15,5 +15,6 @@ package com.google.api.generator.engine.ast; public interface Statement extends AstNode { + @Override void accept(AstNodeVisitor visitor); } diff --git a/src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java b/src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java index c121df71c3..602c0dbf82 100644 --- a/src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java +++ b/src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java @@ -20,6 +20,7 @@ @AutoValue public abstract class StringObjectValue implements ObjectValue { + @Override public abstract String value(); @Override diff --git a/src/main/java/com/google/api/generator/engine/ast/TypeNode.java b/src/main/java/com/google/api/generator/engine/ast/TypeNode.java index 99de1a213d..50bcc62657 100644 --- a/src/main/java/com/google/api/generator/engine/ast/TypeNode.java +++ b/src/main/java/com/google/api/generator/engine/ast/TypeNode.java @@ -112,7 +112,7 @@ public int compareTo(TypeNode other) { return -1; } - if (this.equals(TypeNode.NULL)) { + if (equals(TypeNode.NULL)) { // Can't self-compare, so we don't need to check whether the other one is TypeNode.NULL. return other.isPrimitiveType() ? 1 : -1; } @@ -161,7 +161,7 @@ public static TypeNode withReference(Reference reference) { return TypeNode.builder().setTypeKind(TypeKind.OBJECT).setReference(reference).build(); } - public static TypeNode withExceptionClazz(Class clazz) { + public static TypeNode withExceptionClazz(Class clazz) { Preconditions.checkState(Exception.class.isAssignableFrom(clazz)); return withReference(ConcreteReference.withClazz(clazz)); } @@ -200,11 +200,11 @@ public boolean isPrimitiveType() { } public boolean isProtoPrimitiveType() { - return isPrimitiveType() || this.equals(TypeNode.STRING) || this.equals(TypeNode.BYTESTRING); + return isPrimitiveType() || equals(TypeNode.STRING) || equals(TypeNode.BYTESTRING); } public boolean isSupertypeOrEquals(TypeNode other) { - boolean oneTypeIsNull = this.equals(TypeNode.NULL) ^ other.equals(TypeNode.NULL); + boolean oneTypeIsNull = equals(TypeNode.NULL) ^ other.equals(TypeNode.NULL); return !isPrimitiveType() && !other.isPrimitiveType() && isArray() == other.isArray() @@ -256,20 +256,6 @@ boolean isBoxedTypeEquals(TypeNode other) { return Objects.equals(other, BOXED_TYPE_MAP.get(this)); } - private static TypeNode createPrimitiveType(TypeKind typeKind) { - if (!isPrimitiveType(typeKind)) { - throw new IllegalArgumentException("Object is not a primitive type."); - } - return TypeNode.builder().setTypeKind(typeKind).build(); - } - - private static TypeNode createPrimitiveArrayType(TypeKind typeKind) { - if (typeKind.equals(TypeKind.OBJECT)) { - throw new IllegalArgumentException("Object is not a primitive type."); - } - return TypeNode.builder().setTypeKind(typeKind).setIsArray(true).build(); - } - private static boolean isPrimitiveType(TypeKind typeKind) { return !typeKind.equals(TypeKind.OBJECT); } diff --git a/src/main/java/com/google/api/generator/engine/ast/UnaryOperationExpr.java b/src/main/java/com/google/api/generator/engine/ast/UnaryOperationExpr.java index 74bda2f21d..3a968b92e0 100644 --- a/src/main/java/com/google/api/generator/engine/ast/UnaryOperationExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/UnaryOperationExpr.java @@ -22,10 +22,13 @@ public abstract class UnaryOperationExpr implements OperationExpr { public abstract Expr expr(); + @Override public abstract OperatorKind operatorKind(); + @Override public abstract TypeNode type(); + @Override public void accept(AstNodeVisitor visitor) { visitor.visit(this); } diff --git a/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java b/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java index 58fb2b9aa4..aec153d2f6 100644 --- a/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java +++ b/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java @@ -74,7 +74,6 @@ public class ImportWriterVisitor implements AstNodeVisitor { private static final String DOT = "."; - private static final String NEWLINE = "\n"; private static final String PKG_JAVA_LANG = "java.lang"; private final Set staticImports = new TreeSet<>(); @@ -94,7 +93,7 @@ public void clear() { public void initialize(@Nonnull String currentPackage) { this.currentPackage = currentPackage; - this.currentClassName = null; + currentClassName = null; } public void initialize(@Nonnull String currentPackage, @Nonnull String currentClassName) { @@ -124,7 +123,8 @@ public boolean collidesWithImport(String pakkage, String shortName) { updateShortNames(); } return importShortNames.contains(shortName) - && imports.stream() + && imports + .stream() .filter(s -> s.equals(String.format("%s.%s", pakkage, shortName))) .findFirst() .orElse("") diff --git a/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java b/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java index a52b584da1..b1d750157e 100644 --- a/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java +++ b/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java @@ -81,7 +81,6 @@ public class JavaWriterVisitor implements AstNodeVisitor { private static final String BLOCK_COMMENT_START = "/*"; private static final String BLOCK_COMMENT_END = "*/"; private static final String DOT = "."; - private static final String ESCAPED_QUOTE = "\""; private static final String EQUALS = "="; private static final String LEFT_ANGLE = "<"; private static final String LEFT_BRACE = "{"; @@ -751,6 +750,7 @@ public void visit(BreakStatement breakStatement) { } /** =============================== COMMENT =============================== */ + @Override public void visit(LineComment lineComment) { // Split comments by new line and add `//` to each line. String formattedSource = @@ -759,6 +759,7 @@ public void visit(LineComment lineComment) { buffer.append(formattedSource); } + @Override public void visit(BlockComment blockComment) { // Split comments by new line and embrace the comment block with `/* */`. StringBuilder sourceComment = new StringBuilder(); @@ -772,6 +773,7 @@ public void visit(BlockComment blockComment) { buffer.append(JavaFormatter.format(sourceComment.toString())); } + @Override public void visit(JavaDocComment javaDocComment) { StringBuilder sourceComment = new StringBuilder(); sourceComment.append(JAVADOC_COMMENT_START).append(NEWLINE); @@ -865,7 +867,6 @@ public void visit(MethodDefinition methodDefinition) { buffer.append(THROWS); space(); - int numExceptionsThrown = methodDefinition.throwsExceptions().size(); Iterator exceptionIter = methodDefinition.throwsExceptions().iterator(); while (exceptionIter.hasNext()) { TypeNode exceptionType = exceptionIter.next(); diff --git a/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java b/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java index 8ffeace7c5..e8f8a05681 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java @@ -33,7 +33,6 @@ public class ServiceClientCommentComposer { // Tokens. - private static final String COLON = ":"; private static final String EMPTY_STRING = ""; private static final String API_EXCEPTION_TYPE_NAME = "com.google.api.gax.rpc.ApiException"; private static final String EXCEPTION_CONDITION = "if the remote call fails"; diff --git a/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java b/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java index ec8ef19be4..7f2c83e4a2 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java @@ -27,7 +27,6 @@ public class SettingsCommentComposer { private static final String COLON = ":"; - private static final String STUB_PATTERN = "%sStub"; private static final String BUILDER_CLASS_DOC_PATTERN = "Builder for %s."; private static final String CALL_SETTINGS_METHOD_DOC_PATTERN = "Returns the object with the settings used for calls to %s."; diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceCallableFactoryClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceCallableFactoryClassComposer.java index 4342a4aa80..cdcfee5ee4 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceCallableFactoryClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceCallableFactoryClassComposer.java @@ -131,11 +131,13 @@ protected MethodDefinition createUnaryCallableMethod(TypeStore typeStore) { /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*transportCallSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*transportCallSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -157,7 +159,8 @@ protected MethodDefinition createPagedCallableMethod(TypeStore typeStore) { /*transportCallSettingsTemplateObjects=*/ Arrays.asList( requestTemplateName, responseTemplateName), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -173,11 +176,13 @@ protected MethodDefinition createBatchingCallableMethod(TypeStore typeStore) { /*returnCallableKindName=*/ "Unary", /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*transportCallSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*transportCallSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -269,7 +274,8 @@ protected MethodDefinition createGenericCallableMethod( .setMethodName(methodName) .setStaticReferenceType(getTransportContext().transportCallableFactoryType()) .setArguments( - arguments.stream() + arguments + .stream() .map(v -> v.toBuilder().setIsDecl(false).build()) .collect(Collectors.toList())) .setReturnType(returnType) @@ -289,7 +295,7 @@ protected MethodDefinition createGenericCallableMethod( } private static TypeStore createTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( // Gax-java classes. BatchingCallSettings.class, diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java index e680530d5f..8acb2833a9 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java @@ -108,9 +108,6 @@ public abstract class AbstractServiceClientClassComposer implements ClassCompose private static final Reference LIST_REFERENCE = ConcreteReference.withClazz(List.class); private static final Reference MAP_REFERENCE = ConcreteReference.withClazz(Map.class); - private static final TypeNode OBJECTS_TYPE = - TypeNode.withReference(ConcreteReference.withClazz(Objects.class)); - private enum CallableMethodKind { REGULAR, LRO, @@ -237,7 +234,9 @@ private List createFieldDeclarations( } } - return fieldNameToTypes.entrySet().stream() + return fieldNameToTypes + .entrySet() + .stream() .map( e -> { String varName = e.getKey(); @@ -363,7 +362,6 @@ private List createConstructorMethods( TypeNode stubSettingsType = typeStore.get(ClassNames.getServiceStubSettingsClassName(service)); TypeNode exceptionType = typeStore.get("IOException"); - TypeNode settingsType = typeStore.get(settingsName); VariableExpr settingsVarExpr = VariableExpr.withVariable( Variable.builder().setName("settings").setType(typeStore.get(settingsName)).build()); @@ -418,7 +416,8 @@ private List createConstructorMethods( .setArguments(settingsVarExpr.toBuilder().setIsDecl(true).build()) .setThrowsExceptions(Arrays.asList(exceptionType)) .setBody( - ctorAssignmentExprs.stream() + ctorAssignmentExprs + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build()); @@ -451,7 +450,8 @@ private List createConstructorMethods( .setReturnType(thisClassType) .setArguments(stubVarExpr.toBuilder().setIsDecl(true).build()) .setBody( - ctorAssignmentExprs.stream() + ctorAssignmentExprs + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build()); @@ -515,10 +515,11 @@ private List createGetterMethods( if (hasLroClient) { Iterator opClientNamesIt = getTransportContext().operationsClientNames().iterator(); - Iterator opClientTypesIt = getTransportContext().operationsClientTypes().iterator(); + Iterator opClientTypesIt = getTransportContext().operationsClientTypes().iterator(); while (opClientNamesIt.hasNext() && opClientTypesIt.hasNext()) { - String opClientMethodName = String.format("get%s", JavaStyle.toUpperCamelCase(opClientNamesIt.next())); + String opClientMethodName = + String.format("get%s", JavaStyle.toUpperCamelCase(opClientNamesIt.next())); getOperationsClientMethodNames.add(opClientMethodName); methodNameToTypes.put(opClientMethodName, opClientTypesIt.next()); } @@ -530,7 +531,9 @@ private List createGetterMethods( "A restructuring of stub classes is planned, so this may break in the future") .build(); - return methodNameToTypes.entrySet().stream() + return methodNameToTypes + .entrySet() + .stream() .map( e -> { String methodName = e.getKey(); @@ -589,7 +592,8 @@ private static List createServiceMethods( grpcRpcToJavaMethodMetadata .get(method.name()) .addAll( - generatedMethods.stream() + generatedMethods + .stream() .map(m -> javaMethodNameFn.apply(m)) .collect(Collectors.toList())); javaMethods.addAll(generatedMethods); @@ -657,11 +661,11 @@ private static List createMethodVariants( lro.responseType().reference(), lro.metadataType().reference()))); } - String methodInputTypeName = methodInputType.reference().name(); for (List signature : method.methodSignatures()) { // Get the argument list. List arguments = - signature.stream() + signature + .stream() .map( methodArg -> VariableExpr.builder() @@ -1052,7 +1056,8 @@ private static List createBackgroundResourceMethods( .setReturnType(TypeNode.BOOLEAN) .setName("awaitTermination") .setArguments( - arguments.stream() + arguments + .stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setThrowsExceptions(Arrays.asList(typeStore.get("InterruptedException"))) @@ -1196,12 +1201,6 @@ private static ClassDefinition createNestedRpcPagedResponseClass( VariableExpr inputVarExpr = VariableExpr.withVariable( Variable.builder().setName("input").setType(methodPageType).build()); - TypeNode anonClassType = - TypeNode.withReference( - ConcreteReference.builder() - .setClazz(ApiFunction.class) - .setGenerics(Arrays.asList(methodPageType.reference(), thisClassType.reference())) - .build()); // Overrides ApiFunction.apply. // (https://github.com/googleapis/api-common-java/blob/debf25960dea0367b0d3b5e16d57d76c1d01947e/src/main/java/com/google/api/core/ApiFunction.java). @@ -1240,7 +1239,8 @@ private static ClassDefinition createNestedRpcPagedResponseClass( .setReturnType(returnType) .setName("createAsync") .setArguments( - Arrays.asList(contextVarExpr, futureResponseVarExpr).stream() + Arrays.asList(contextVarExpr, futureResponseVarExpr) + .stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody(Arrays.asList(ExprStatement.withExpr(futurePageAssignExpr))) @@ -1341,7 +1341,8 @@ private static ClassDefinition createNestedRpcPageClass( .setScope(ScopeNode.PRIVATE) .setReturnType(classType) .setArguments( - Arrays.asList(contextVarExpr, responseVarExpr).stream() + Arrays.asList(contextVarExpr, responseVarExpr) + .stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody( @@ -1373,7 +1374,8 @@ private static ClassDefinition createNestedRpcPageClass( .setReturnType(classType) .setName("createPage") .setArguments( - Arrays.asList(contextVarExpr, responseVarExpr).stream() + Arrays.asList(contextVarExpr, responseVarExpr) + .stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr( @@ -1405,7 +1407,8 @@ private static ClassDefinition createNestedRpcPageClass( .setReturnType(futurePageType) .setName("createPageAsync") .setArguments( - Arrays.asList(contextVarExpr, futureResponseVarExpr).stream() + Arrays.asList(contextVarExpr, futureResponseVarExpr) + .stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr( @@ -1482,7 +1485,8 @@ private static ClassDefinition createNestedRpcFixedSizeCollectionClass( .setScope(ScopeNode.PRIVATE) .setReturnType(classType) .setArguments( - Arrays.asList(pagesVarExpr, collectionSizeVarExpr).stream() + Arrays.asList(pagesVarExpr, collectionSizeVarExpr) + .stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody( @@ -1519,7 +1523,8 @@ private static ClassDefinition createNestedRpcFixedSizeCollectionClass( .setReturnType(classType) .setName("createCollection") .setArguments( - Arrays.asList(pagesVarExpr, collectionSizeVarExpr).stream() + Arrays.asList(pagesVarExpr, collectionSizeVarExpr) + .stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr( @@ -1562,7 +1567,7 @@ static Expr createRequestBuilderExpr( rootFields.add(rootField); } Trie updatedTrie = - rootFieldToTrie.containsKey(rootField) ? rootFieldToTrie.get(rootField) : new Trie(); + rootFieldToTrie.containsKey(rootField) ? rootFieldToTrie.get(rootField) : new Trie<>(); List nestedFieldsWithChild = new ArrayList<>(arg.nestedFields()); nestedFieldsWithChild.add(arg.field()); updatedTrie.insert(nestedFieldsWithChild); @@ -1661,7 +1666,7 @@ private static String typeToSetterMethodName(TypeNode type) { } private static TypeStore createTypes(Service service, Map messageTypes) { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( AbstractPagedListResponse.class, ApiFunction.class, @@ -1711,7 +1716,8 @@ private static void createVaporTypes(Service service, TypeStore typeStore) { } typeStore.putAll( service.pakkage(), - Arrays.asList("%sPagedResponse", "%sPage", "%sFixedSizeCollection").stream() + Arrays.asList("%sPagedResponse", "%sPage", "%sFixedSizeCollection") + .stream() .map(p -> String.format(p, JavaStyle.toUpperCamelCase(method.name()))) .collect(Collectors.toList()), true, @@ -1721,7 +1727,9 @@ private static void createVaporTypes(Service service, TypeStore typeStore) { // Pagination types. typeStore.putAll( service.pakkage(), - service.methods().stream() + service + .methods() + .stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), @@ -1762,15 +1770,6 @@ private static boolean isProtoEmptyType(TypeNode type) { && type.reference().name().equals("Empty"); } - private static void updateGapicMetadata( - GapicContext context, String protoPackage, String javaPackage) { - context.updateGapicMetadata( - context.gapicMetadata().toBuilder() - .setProtoPackage(protoPackage) - .setLibraryPackage(javaPackage) - .build()); - } - private static void updateGapicMetadata( GapicContext context, Service service, diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java index 364dd183b3..c561dbd36a 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java @@ -20,13 +20,8 @@ import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.ClientStreamingCallable; import com.google.api.gax.rpc.InvalidArgumentException; -import com.google.api.gax.rpc.OperationCallSettings; -import com.google.api.gax.rpc.PagedCallSettings; -import com.google.api.gax.rpc.ServerStreamingCallSettings; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.StatusCode; -import com.google.api.gax.rpc.StreamingCallSettings; -import com.google.api.gax.rpc.UnaryCallSettings; import com.google.api.generator.engine.ast.AnnotationNode; import com.google.api.generator.engine.ast.AssignmentExpr; import com.google.api.generator.engine.ast.ClassDefinition; @@ -156,7 +151,9 @@ protected List createClassMemberFieldDecls( // Static fields go first. fieldDeclStatements.addAll( - classMemberVarExprs.values().stream() + classMemberVarExprs + .values() + .stream() .filter(v -> isMockVarExprFn.apply(v)) .map( v -> @@ -169,7 +166,9 @@ protected List createClassMemberFieldDecls( .collect(Collectors.toList())); fieldDeclStatements.addAll( - classMemberVarExprs.values().stream() + classMemberVarExprs + .values() + .stream() .filter(v -> !isMockVarExprFn.apply(v)) .map( v -> @@ -236,7 +235,9 @@ private List createTestMethods( String mixinServiceName = method.mixedInApiName().substring(dotIndex + 1); String mixinServiceProtoPackage = method.mixedInApiName().substring(0, dotIndex); Optional mixinServiceOpt = - context.mixinServices().stream() + context + .mixinServices() + .stream() .filter( s -> s.name().equals(mixinServiceName) @@ -829,7 +830,8 @@ protected List createRpcExceptionTestStatements( TryCatchStatement tryCatchBlock = TryCatchStatement.builder() .setTryBody( - tryBodyExprs.stream() + tryBodyExprs + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .addCatch(catchExceptionVarExpr.toBuilder().setIsDecl(true).build(), catchBody) @@ -847,7 +849,7 @@ protected abstract List createRpcLroExceptionTestCatchBody( */ private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( AbstractMessage.class, After.class, @@ -889,7 +891,9 @@ private void addDynamicTypes(GapicContext context, Service service, TypeStore ty // Pagination types. typeStore.putAll( service.pakkage(), - service.methods().stream() + service + .methods() + .stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), @@ -910,70 +914,12 @@ private void addDynamicTypes(GapicContext context, Service service, TypeStore ty } } - private static TypeNode getOperationCallSettingsTypeHelper( - Method protoMethod, boolean isBuilder) { - Preconditions.checkState( - protoMethod.hasLro(), - String.format("Cannot get OperationCallSettings on non-LRO method %s", protoMethod.name())); - Class callSettingsClazz = - isBuilder ? OperationCallSettings.Builder.class : OperationCallSettings.class; - return TypeNode.withReference( - ConcreteReference.builder() - .setClazz(callSettingsClazz) - .setGenerics( - Arrays.asList( - protoMethod.inputType().reference(), - protoMethod.lro().responseType().reference(), - protoMethod.lro().metadataType().reference())) - .build()); - } - - private static TypeNode getCallSettingsTypeHelper( - Method protoMethod, TypeStore typeStore, boolean isBuilder) { - Class callSettingsClazz = isBuilder ? UnaryCallSettings.Builder.class : UnaryCallSettings.class; - if (protoMethod.isPaged()) { - callSettingsClazz = isBuilder ? PagedCallSettings.Builder.class : PagedCallSettings.class; - } else { - switch (protoMethod.stream()) { - case CLIENT: - // Fall through. - case BIDI: - callSettingsClazz = - isBuilder ? StreamingCallSettings.Builder.class : StreamingCallSettings.class; - break; - case SERVER: - callSettingsClazz = - isBuilder - ? ServerStreamingCallSettings.Builder.class - : ServerStreamingCallSettings.class; - break; - case NONE: - // Fall through - default: - // Fall through - } - } - - List generics = new ArrayList<>(); - generics.add(protoMethod.inputType().reference()); - generics.add(protoMethod.outputType().reference()); - if (protoMethod.isPaged()) { - generics.add( - typeStore - .get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, protoMethod.name())) - .reference()); - } - - return TypeNode.withReference( - ConcreteReference.builder().setClazz(callSettingsClazz).setGenerics(generics).build()); - } - protected static TypeNode getCallableType(Method protoMethod) { Preconditions.checkState( !protoMethod.stream().equals(Method.Stream.NONE), "No callable type exists for non-streaming methods."); - Class callableClazz = ClientStreamingCallable.class; + Class callableClazz = ClientStreamingCallable.class; switch (protoMethod.stream()) { case BIDI: callableClazz = BidiStreamingCallable.class; diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java index cd4f89cbb9..cea354f002 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java @@ -133,7 +133,9 @@ private static List createClassHeaderComments( service.methods().isEmpty() ? Optional.empty() : Optional.of( - service.methods().stream() + service + .methods() + .stream() .filter(m -> m.stream() == Stream.NONE && !m.hasLro() && !m.isPaged()) .findFirst() .orElse(service.methods().get(0))); @@ -324,7 +326,7 @@ private List createDefaultGetterMethods(Service service, TypeS .build()); BiFunction methodMakerFn = (methodDefBuilder, comment) -> methodDefBuilder.setHeaderCommentStatements(comment).build(); - Function typeMakerFn = + Function, TypeNode> typeMakerFn = c -> TypeNode.withReference(ConcreteReference.withClazz(c)); List javaMethods = new ArrayList<>(); @@ -750,7 +752,7 @@ private static MethodDefinition createNestedBuilderClassBuildMethod( } private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( ApiClientHeaderProvider.class, ApiFunction.class, @@ -793,7 +795,9 @@ private static TypeStore createDynamicTypes(Service service) { // Pagination types. typeStore.putAll( service.pakkage(), - service.methods().stream() + service + .methods() + .stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), @@ -815,7 +819,7 @@ private static TypeNode getOperationCallSettingsTypeHelper( Preconditions.checkState( protoMethod.hasLro(), String.format("Cannot get OperationCallSettings on non-LRO method %s", protoMethod.name())); - Class callSettingsClazz = + Class callSettingsClazz = isBuilder ? OperationCallSettings.Builder.class : OperationCallSettings.class; return TypeNode.withReference( ConcreteReference.builder() @@ -838,7 +842,8 @@ private static TypeNode getCallSettingsBuilderType(Method protoMethod, TypeStore private static TypeNode getCallSettingsTypeHelper( Method protoMethod, TypeStore typeStore, boolean isBuilder) { - Class callSettingsClazz = isBuilder ? UnaryCallSettings.Builder.class : UnaryCallSettings.class; + Class callSettingsClazz = + isBuilder ? UnaryCallSettings.Builder.class : UnaryCallSettings.class; if (protoMethod.isPaged()) { callSettingsClazz = isBuilder ? PagedCallSettings.Builder.class : PagedCallSettings.class; } else if (protoMethod.isBatching()) { diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java index 38a8dd89a3..07c4bb26bc 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java @@ -51,7 +51,6 @@ import javax.annotation.Generated; public abstract class AbstractServiceStubClassComposer implements ClassComposer { - private static final String DOT = "."; private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; private final TransportContext transportContext; @@ -210,7 +209,9 @@ private List createOperationsStubGetters(TypeStore typeStore) String methodName = String.format("get%s", JavaStyle.toUpperCamelCase(operationStubNameIt.next())); - getters.add(createOperationsStubGetterMethodDefinition(operationStubTypeIt.next(), methodName, typeStore)); + getters.add( + createOperationsStubGetterMethodDefinition( + operationStubTypeIt.next(), methodName, typeStore)); } return getters; @@ -229,7 +230,7 @@ private static List createBackgroundResourceMethodOverrides() } private static TypeStore createTypes(Service service, Map messageTypes) { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( BackgroundResource.class, BetaApi.class, @@ -248,7 +249,9 @@ private static TypeStore createTypes(Service service, Map messa // Pagination types. typeStore.putAll( service.pakkage(), - service.methods().stream() + service + .methods() + .stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), @@ -259,7 +262,10 @@ private static TypeStore createTypes(Service service, Map messa } protected MethodDefinition createCallableGetterMethodDefinition( - TypeNode returnType, String methodName, List annotations, TypeStore typeStore) { + TypeNode returnType, + String methodName, + List annotations, + TypeStore typeStore) { return MethodDefinition.builder() .setScope(ScopeNode.PUBLIC) .setAnnotations(annotations) @@ -290,8 +296,4 @@ protected MethodDefinition createOperationsStubGetterMethodDefinition( .build()))) .build(); } - - private static String getClientClassName(Service service) { - return String.format("%sClient", service.overriddenName()); - } } diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java index d61456e1ad..d1cff00c91 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java @@ -373,7 +373,9 @@ private static List createClassHeaderComments( service.methods().isEmpty() ? Optional.empty() : Optional.of( - service.methods().stream() + service + .methods() + .stream() .filter(m -> m.stream() == Stream.NONE && !m.hasLro() && !m.isPaged()) .findFirst() .orElse(service.methods().get(0))); @@ -449,7 +451,8 @@ private static List createClassStatements( // Assign DEFAULT_SERVICE_SCOPES. statements.add(SettingsCommentComposer.DEFAULT_SCOPES_COMMENT); VariableExpr defaultServiceScopesDeclVarExpr = - DEFAULT_SERVICE_SCOPES_VAR_EXPR.toBuilder() + DEFAULT_SERVICE_SCOPES_VAR_EXPR + .toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) @@ -486,7 +489,9 @@ private static List createClassStatements( // Declare settings members. statements.addAll( - methodSettingsMemberVarExprs.values().stream() + methodSettingsMemberVarExprs + .values() + .stream() .map( v -> exprToStatementFn.apply( @@ -639,7 +644,8 @@ private static Expr createPagedListDescriptorAssignExpr( .setReturnType(method.inputType()) .setName("injectToken") .setArguments( - Arrays.asList(payloadVarExpr, strTokenVarExpr).stream() + Arrays.asList(payloadVarExpr, strTokenVarExpr) + .stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr(returnExpr) @@ -668,7 +674,8 @@ private static Expr createPagedListDescriptorAssignExpr( .setReturnType(method.inputType()) .setName("injectPageSize") .setArguments( - Arrays.asList(payloadVarExpr, pageSizeVarExpr).stream() + Arrays.asList(payloadVarExpr, pageSizeVarExpr) + .stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr(returnExpr) @@ -799,7 +806,8 @@ private static Expr createPagedListDescriptorAssignExpr( // Declare and assign the variable. return AssignmentExpr.builder() .setVariableExpr( - pagedListDescVarExpr.toBuilder() + pagedListDescVarExpr + .toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) @@ -938,7 +946,8 @@ private static Expr createPagedListResponseFactoryAssignExpr( return AssignmentExpr.builder() .setVariableExpr( - pagedListResponseFactoryVarExpr.toBuilder() + pagedListResponseFactoryVarExpr + .toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) @@ -984,7 +993,9 @@ private static List createMethodSettingsGetterMethods( .setReturnExpr(e.getValue()) .build(); }; - return methodSettingsMemberVarExprs.entrySet().stream() + return methodSettingsMemberVarExprs + .entrySet() + .stream() .map(e -> varToMethodFn.apply(e)) .collect(Collectors.toList()); } @@ -1261,7 +1272,9 @@ private static MethodDefinition createClassConstructor( .build()) .build(); bodyStatements.addAll( - methodSettingsMemberVarExprs.entrySet().stream() + methodSettingsMemberVarExprs + .entrySet() + .stream() .map(e -> ExprStatement.withExpr(varInitExprFn.apply(e))) .collect(Collectors.toList())); @@ -1278,7 +1291,6 @@ private ClassDefinition createNestedBuilderClass( Service service, @Nullable GapicServiceConfig serviceConfig, TypeStore typeStore) { // TODO(miraleung): Robustify this against a null serviceConfig. String thisClassName = ClassNames.getServiceStubSettingsClassName(service); - TypeNode outerThisClassType = typeStore.get(thisClassName); String className = "Builder"; @@ -1287,7 +1299,8 @@ private ClassDefinition createNestedBuilderClass( ConcreteReference.builder() .setClazz(StubSettings.Builder.class) .setGenerics( - Arrays.asList(typeStore.get(thisClassName), typeStore.get(className)).stream() + Arrays.asList(typeStore.get(thisClassName), typeStore.get(className)) + .stream() .map(t -> t.reference()) .collect(Collectors.toList())) .build()); @@ -1337,7 +1350,9 @@ private static List createNestedClassStatements( // Declare all the settings fields. exprs.addAll( - nestedMethodSettingsMemberVarExprs.values().stream() + nestedMethodSettingsMemberVarExprs + .values() + .stream() .map(v -> varDeclFn.apply(v)) .collect(Collectors.toList())); @@ -1535,7 +1550,9 @@ private static List createNestedClassConstructorMethods( ctorBodyStatements.add(EMPTY_LINE_STATEMENT); ctorBodyStatements.addAll( - nestedMethodSettingsMemberVarExprs.entrySet().stream() + nestedMethodSettingsMemberVarExprs + .entrySet() + .stream() .map( e -> { // TODO(miraleung): Extract this into another method. @@ -1644,7 +1661,9 @@ private static List createNestedClassConstructorMethods( .generics()) .setMethodName("of") .setArguments( - nestedMethodSettingsMemberVarExprs.values().stream() + nestedMethodSettingsMemberVarExprs + .values() + .stream() .filter( v -> isUnaryCallSettingsBuilderFn.apply(v.type()) @@ -1690,7 +1709,9 @@ private static List createNestedClassConstructorMethods( // TODO(cleanup): Technically this should actually use the outer class's Settings // members to avoid decoupling variable names. ctorBodyStatements.addAll( - nestedMethodSettingsMemberVarExprs.values().stream() + nestedMethodSettingsMemberVarExprs + .values() + .stream() .map( v -> ExprStatement.withExpr( @@ -1982,7 +2003,7 @@ private static MethodDefinition createNestedClassBuildMethod( } private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( ApiCallContext.class, ApiClientHeaderProvider.class, @@ -2051,7 +2072,9 @@ private TypeStore createDynamicTypes(Service service, String pakkage) { // Pagination types. typeStore.putAll( service.pakkage(), - service.methods().stream() + service + .methods() + .stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), @@ -2103,7 +2126,8 @@ private static VariableExpr createNestedRetryableCodeDefinitionsVarExpr() { ConcreteReference.builder() .setClazz(ImmutableMap.class) .setGenerics( - Arrays.asList(TypeNode.STRING, immutableSetType).stream() + Arrays.asList(TypeNode.STRING, immutableSetType) + .stream() .map(t -> t.reference()) .collect(Collectors.toList())) .build()); @@ -2120,7 +2144,8 @@ private static VariableExpr createNestedRetryParamDefinitionsVarExpr() { ConcreteReference.builder() .setClazz(ImmutableMap.class) .setGenerics( - Arrays.asList(TypeNode.STRING, FIXED_TYPESTORE.get("RetrySettings")).stream() + Arrays.asList(TypeNode.STRING, FIXED_TYPESTORE.get("RetrySettings")) + .stream() .map(t -> t.reference()) .collect(Collectors.toList())) .build()); @@ -2140,7 +2165,7 @@ private static TypeNode getCallSettingsType( TypeStore typeStore, boolean isBatchingSettings, final boolean isSettingsBuilder) { - Function typeMakerFn = + Function, TypeNode> typeMakerFn = clz -> TypeNode.withReference(ConcreteReference.withClazz(clz)); // Default: No streaming. TypeNode callSettingsType = diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java index 26b72a5739..8df5d94803 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java @@ -48,6 +48,7 @@ import com.google.api.generator.engine.ast.VariableExpr; import com.google.api.generator.gapic.composer.comment.StubCommentComposer; import com.google.api.generator.gapic.composer.store.TypeStore; +import com.google.api.generator.gapic.composer.utils.ClassNames; import com.google.api.generator.gapic.composer.utils.PackageChecker; import com.google.api.generator.gapic.model.GapicClass; import com.google.api.generator.gapic.model.GapicClass.Kind; @@ -101,7 +102,7 @@ public TransportContext getTransportContext() { } private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( BackgroundResource.class, BackgroundResourceAggregation.class, @@ -181,8 +182,7 @@ public GapicClass generate(GapicContext context, Service service) { .setAnnotations(createClassAnnotations(service)) .setScope(ScopeNode.PUBLIC) .setName(className) - .setExtendsType( - typeStore.get(getTransportContext().classNames().getServiceStubClassName(service))) + .setExtendsType(typeStore.get(ClassNames.getServiceStubClassName(service))) .setStatements(classStatements) .setMethods( createClassMethods( @@ -211,7 +211,8 @@ protected List createOperationsStubGetterMethod( String methodName = String.format( "get%s", - JavaStyle.toUpperCamelCase(getTransportContext().transportOperationsStubNames().get(0))); + JavaStyle.toUpperCamelCase( + getTransportContext().transportOperationsStubNames().get(0))); return Arrays.asList( MethodDefinition.builder() @@ -253,7 +254,9 @@ protected List createClassStatements( protected List createMethodDescriptorVariableDecls( Service service, Map protoMethodNameToDescriptorVarExprs) { - return service.methods().stream() + return service + .methods() + .stream() .map( m -> createMethodDescriptorVariableDecl( @@ -263,7 +266,9 @@ protected List createMethodDescriptorVariableDecls( private static List createClassMemberFieldDeclarations( Map fieldNameToVarExprs) { - return fieldNameToVarExprs.values().stream() + return fieldNameToVarExprs + .values() + .stream() .map( v -> ExprStatement.withExpr( @@ -277,7 +282,9 @@ private static List createClassMemberFieldDeclarations( protected Map createProtoMethodNameToDescriptorClassMembers( Service service, Class descriptorClass) { - return service.methods().stream() + return service + .methods() + .stream() .collect( Collectors.toMap( Method::name, @@ -401,14 +408,16 @@ protected List createClassMethods( createGetMethodDescriptorsMethod(service, typeStore, protoMethodNameToDescriptorVarExprs)); javaMethods.addAll( createOperationsStubGetterMethod( - service, classMemberVarExprs.get(getTransportContext().transportOperationsStubNames().get(0)))); + service, + classMemberVarExprs.get(getTransportContext().transportOperationsStubNames().get(0)))); javaMethods.addAll(createCallableGetterMethods(callableClassMemberVarExprs)); javaMethods.addAll( createStubOverrideMethods(classMemberVarExprs.get(BACKGROUND_RESOURCES_MEMBER_NAME))); return javaMethods; } - protected List createStaticCreatorMethods(Service service, TypeStore typeStore, String newBuilderMethod) { + protected List createStaticCreatorMethods( + Service service, TypeStore typeStore, String newBuilderMethod) { TypeNode creatorMethodReturnType = typeStore.get(getTransportContext().classNames().getTransportServiceStubClassName(service)); Function, MethodDefinition.Builder> creatorMethodStarterFn = @@ -420,7 +429,8 @@ protected List createStaticCreatorMethods(Service service, Typ .setReturnType(creatorMethodReturnType) .setName("create") .setArguments( - argList.stream() + argList + .stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setThrowsExceptions( @@ -431,8 +441,7 @@ protected List createStaticCreatorMethods(Service service, Typ argList -> NewObjectExpr.builder().setType(creatorMethodReturnType).setArguments(argList).build(); - TypeNode stubSettingsType = - typeStore.get(getTransportContext().classNames().getServiceStubSettingsClassName(service)); + TypeNode stubSettingsType = typeStore.get(ClassNames.getServiceStubSettingsClassName(service)); VariableExpr settingsVarExpr = VariableExpr.withVariable( Variable.builder().setName("settings").setType(stubSettingsType).build()); @@ -494,8 +503,7 @@ protected List createConstructorMethods( Map classMemberVarExprs, Map callableClassMemberVarExprs, Map protoMethodNameToDescriptorVarExprs) { - TypeNode stubSettingsType = - typeStore.get(getTransportContext().classNames().getServiceStubSettingsClassName(service)); + TypeNode stubSettingsType = typeStore.get(ClassNames.getServiceStubSettingsClassName(service)); VariableExpr settingsVarExpr = VariableExpr.withVariable( Variable.builder().setName("settings").setType(stubSettingsType).build()); @@ -562,12 +570,15 @@ protected List createConstructorMethods( secondCtorExprs.add( AssignmentExpr.builder() .setVariableExpr( - classMemberVarExprs.get("callableFactory").toBuilder() + classMemberVarExprs + .get("callableFactory") + .toBuilder() .setExprReferenceExpr(thisExpr) .build()) .setValueExpr(callableFactoryVarExpr) .build()); - VariableExpr operationsStubClassVarExpr = classMemberVarExprs.get(getTransportContext().transportOperationsStubNames().get(0)); + VariableExpr operationsStubClassVarExpr = + classMemberVarExprs.get(getTransportContext().transportOperationsStubNames().get(0)); if (generateOperationsStubLogic(service)) { secondCtorExprs.add( AssignmentExpr.builder() @@ -575,7 +586,8 @@ protected List createConstructorMethods( operationsStubClassVarExpr.toBuilder().setExprReferenceExpr(thisExpr).build()) .setValueExpr( MethodInvocationExpr.builder() - .setStaticReferenceType(getTransportContext().transportOperationsStubTypes().get(0)) + .setStaticReferenceType( + getTransportContext().transportOperationsStubTypes().get(0)) .setMethodName("create") .setArguments(Arrays.asList(clientContextVarExpr, callableFactoryVarExpr)) .setReturnType(operationsStubClassVarExpr.type()) @@ -589,7 +601,9 @@ protected List createConstructorMethods( // Transport settings local variables. Map javaStyleMethodNameToTransportSettingsVarExprs = - service.methods().stream() + service + .methods() + .stream() .collect( Collectors.toMap( m -> JavaStyle.toLowerCamelCase(m.name()), @@ -612,7 +626,9 @@ protected List createConstructorMethods( .build()))); secondCtorExprs.addAll( - service.methods().stream() + service + .methods() + .stream() .map( m -> createTransportSettingsInitExpr( @@ -628,7 +644,9 @@ protected List createConstructorMethods( // Initialize Callable variables. secondCtorExprs.addAll( - callableClassMemberVarExprs.entrySet().stream() + callableClassMemberVarExprs + .entrySet() + .stream() .map( e -> createCallableInitExpr( @@ -778,7 +796,9 @@ protected Optional getCallableCreatorMethodName(TypeNode callableVarExpr private static List createCallableGetterMethods( Map callableClassMemberVarExprs) { - return callableClassMemberVarExprs.entrySet().stream() + return callableClassMemberVarExprs + .entrySet() + .stream() .map( e -> MethodDefinition.builder() @@ -910,7 +930,8 @@ private List createStubOverrideMethods( .apply("awaitTermination") .setReturnType(TypeNode.BOOLEAN) .setArguments( - awaitTerminationArgs.stream() + awaitTerminationArgs + .stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setThrowsExceptions(Arrays.asList(FIXED_TYPESTORE.get("InterruptedException"))) @@ -919,7 +940,8 @@ private List createStubOverrideMethods( .setExprReferenceExpr(backgroundResourcesVarExpr) .setMethodName("awaitTermination") .setArguments( - awaitTerminationArgs.stream() + awaitTerminationArgs + .stream() .map(v -> (Expr) v) .collect(Collectors.toList())) .setReturnType(TypeNode.BOOLEAN) @@ -934,20 +956,22 @@ private TypeStore createDynamicTypes(Service service, String stubPakkage) { stubPakkage, Arrays.asList( getTransportContext().classNames().getTransportServiceStubClassName(service), - getTransportContext().classNames().getServiceStubSettingsClassName(service), - getTransportContext().classNames().getServiceStubClassName(service), + ClassNames.getServiceStubSettingsClassName(service), + ClassNames.getServiceStubClassName(service), getTransportContext() .classNames() .getTransportServiceCallableFactoryClassName(service))); // Pagination types. typeStore.putAll( service.pakkage(), - service.methods().stream() + service + .methods() + .stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), true, - getTransportContext().classNames().getServiceClientClassName(service)); + ClassNames.getServiceClientClassName(service)); return typeStore; } diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposer.java index 8de7d4c9c2..cc47a8db20 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposer.java @@ -66,7 +66,6 @@ public class BatchingDescriptorComposer { private static final TypeNode PARTITION_KEY_TYPE = toType(PartitionKey.class); private static final String ADD_ALL_METHOD_PATTERN = "addAll%s"; - private static final String BATCH_FOO_INDEX_PATTERN = "batch%sIndex"; private static final String GET_LIST_METHOD_PATTERN = "get%sList"; private static final String GET_COUNT_METHOD_PATTERN = "get%sCount"; @@ -272,8 +271,6 @@ private static MethodDefinition createSplitResponseMethod( VariableExpr.withVariable( Variable.builder().setType(batchedRequestIssuerType).setName("responder").build()); - String upperCamelBatchedFieldName = - JavaStyle.toUpperCamelCase(batchingSettings.batchedFieldName()); VariableExpr batchMessageIndexVarExpr = VariableExpr.withVariable( Variable.builder().setType(TypeNode.INT).setName("batchMessageIndex").build()); @@ -361,7 +358,8 @@ private static MethodDefinition createSplitResponseMethod( forIndexVarExpr, initValueExpr, subresponseCountVarExpr, - innerSubresponseForExprs.stream() + innerSubresponseForExprs + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())); @@ -441,7 +439,8 @@ private static MethodDefinition createSplitResponseMethod( .setReturnType(TypeNode.VOID) .setName("splitResponse") .setArguments( - Arrays.asList(batchResponseVarExpr, batchVarExpr).stream() + Arrays.asList(batchResponseVarExpr, batchVarExpr) + .stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody(bodyStatements) @@ -490,7 +489,8 @@ private static MethodDefinition createSplitExceptionMethod(Method method) { .setReturnType(TypeNode.VOID) .setName("splitException") .setArguments( - Arrays.asList(throwableVarExpr, batchVarExpr).stream() + Arrays.asList(throwableVarExpr, batchVarExpr) + .stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody(Arrays.asList(forStatement)) @@ -541,7 +541,7 @@ private static MethodDefinition createCountByteSMethod(Method method) { .build(); } - private static TypeNode toType(Class clazz) { + private static TypeNode toType(Class clazz) { return TypeNode.withReference(ConcreteReference.withClazz(clazz)); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java index 4497495d67..05dd660148 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java @@ -474,7 +474,8 @@ private static Expr createRetryCodeDefinitionExpr( .setGenerics(Arrays.asList(STATUS_CODE_CODE_TYPE.reference())) .setMethodName("newArrayList") .setArguments( - retryCodes.stream() + retryCodes + .stream() .map(c -> toStatusCodeEnumRefExpr(c)) .collect(Collectors.toList())) .build(); @@ -711,7 +712,7 @@ private static MethodInvocationExpr createDurationOfMillisExpr(ValueExpr valExpr } private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( BatchingSettings.class, org.threeten.bp.Duration.class, diff --git a/src/main/java/com/google/api/generator/gapic/composer/defaultvalue/DefaultValueComposer.java b/src/main/java/com/google/api/generator/gapic/composer/defaultvalue/DefaultValueComposer.java index 5af2722fd7..0be270c1c8 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/defaultvalue/DefaultValueComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/defaultvalue/DefaultValueComposer.java @@ -40,7 +40,6 @@ import com.google.common.base.Preconditions; import com.google.longrunning.Operation; import com.google.protobuf.Any; -import com.google.protobuf.ByteString; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -54,8 +53,6 @@ public class DefaultValueComposer { private static TypeNode OPERATION_TYPE = TypeNode.withReference(ConcreteReference.withClazz(Operation.class)); private static TypeNode ANY_TYPE = TypeNode.withReference(ConcreteReference.withClazz(Any.class)); - private static TypeNode BYTESTRING_TYPE = - TypeNode.withReference(ConcreteReference.withClazz(ByteString.class)); public static Expr createDefaultValue( MethodArgument methodArg, @@ -237,14 +234,16 @@ static Expr createDefaultValueResourceHelper( "of%sName", String.join( "", - patternPlaceholderTokens.stream() + patternPlaceholderTokens + .stream() .map(s -> JavaStyle.toUpperCamelCase(s)) .collect(Collectors.toList()))); } TypeNode resourceNameJavaType = resourceName.type(); List argExprs = - patternPlaceholderTokens.stream() + patternPlaceholderTokens + .stream() .map( s -> ValueExpr.withValue( diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceCallableFactoryClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceCallableFactoryClassComposer.java index 5698f5a443..d894d8b4f9 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceCallableFactoryClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceCallableFactoryClassComposer.java @@ -45,6 +45,7 @@ protected List createClassImplements(TypeStore typeStore) { return Arrays.asList(getTransportContext().stubCallableFactoryType()); } + @Override protected List createClassMethods(TypeStore typeStore) { List classMethods = new ArrayList<>(super.createClassMethods(typeStore)); classMethods.addAll( @@ -55,6 +56,7 @@ protected List createClassMethods(TypeStore typeStore) { return classMethods; } + @Override protected MethodDefinition createUnaryCallableMethod(TypeStore typeStore) { String methodVariantName = "Unary"; String requestTemplateName = "RequestT"; @@ -66,15 +68,18 @@ protected MethodDefinition createUnaryCallableMethod(TypeStore typeStore) { /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList())); } + @Override protected MethodDefinition createPagedCallableMethod(TypeStore typeStore) { String methodVariantName = "Paged"; String requestTemplateName = "RequestT"; @@ -92,7 +97,8 @@ protected MethodDefinition createPagedCallableMethod(TypeStore typeStore) { /*grpcCallSettingsTemplateObjects=*/ Arrays.asList( requestTemplateName, responseTemplateName), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -112,7 +118,8 @@ protected MethodDefinition createOperationCallableMethod(TypeStore typeStore) { /*methodVariantName=*/ methodVariantName, /*grpcCallSettingsTemplateObjects=*/ Arrays.asList(requestTemplateName, OPERATION_TYPE), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -128,11 +135,13 @@ private MethodDefinition createBidiStreamingCallableMethod(TypeStore typeStore) /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ "Streaming", - /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -148,11 +157,13 @@ private MethodDefinition createServerStreamingCallableMethod(TypeStore typeStore /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -168,11 +179,13 @@ private MethodDefinition createClientStreamingCallableMethod(TypeStore typeStore /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ "Streaming", - /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames + .stream() .map(n -> (Object) n) .collect(Collectors.toList())); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java index 22e986adb0..578ce02005 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java @@ -72,7 +72,7 @@ public static GrpcServiceStubClassComposer instance() { } private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( GrpcCallSettings.class, GrpcOperationsStub.class, @@ -254,9 +254,6 @@ private LambdaExpr createRequestParamsExtractorClassInstance(Method method) { VariableExpr paramsVarExpr = VariableExpr.withVariable( Variable.builder().setName("params").setType(paramsVarType).build()); - VariableExpr reqeustVarExpr = - VariableExpr.withVariable( - Variable.builder().setName("request").setType(method.inputType()).build()); Expr paramsAssignExpr = AssignmentExpr.builder() diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceClassComposer.java index f1ac25fd06..7227b4fe4a 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceClassComposer.java @@ -234,7 +234,7 @@ private static MethodDefinition createResetMethod(VariableExpr serviceImplVarExp } private static TypeStore createTypes(Service service) { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( AbstractMessage.class, BetaApi.class, Generated.class, ServerServiceDefinition.class); TypeStore typeStore = new TypeStore(concreteClazzes); diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceImplClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceImplClassComposer.java index 2f77f6aa75..f2c1edde1f 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceImplClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceImplClassComposer.java @@ -98,7 +98,10 @@ public GapicClass generate(GapicContext context, Service service) { // Use the full name java.lang.Object if there is a proto message that is also named "Object". // Affects GCS. - if (context.messages().keySet().stream() + if (context + .messages() + .keySet() + .stream() .anyMatch(s -> s.equals("Object") || s.endsWith(".Object"))) { javaObjectReference = ConcreteReference.builder().setClazz(Object.class).setUseFullName(true).build(); @@ -271,7 +274,9 @@ private static MethodDefinition createResetMethod() { } private static List createProtoMethodOverrides(Service service) { - return service.methods().stream() + return service + .methods() + .stream() .filter(m -> !m.isMixin()) // Mixin APIs will get their own generated mocks. .map(m -> createGenericProtoMethodOverride(m)) .collect(Collectors.toList()); @@ -596,7 +601,7 @@ private static Statement createHandleObjectStatement( } private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( AbstractMessage.class, ArrayList.class, @@ -646,7 +651,8 @@ private static List createRequestResponseAssignStatements() { .setIsGeneric(true) .build()) .build(); - return Arrays.asList(assignRequestVarExpr, assignResponsesVarExpr).stream() + return Arrays.asList(assignRequestVarExpr, assignResponsesVarExpr) + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList()); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java index 75bd4c0133..f2bba0459e 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java @@ -96,7 +96,7 @@ public static AbstractServiceClientTestClassComposer instance() { } private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( GaxGrpcProperties.class, LocalChannelProvider.class, @@ -127,7 +127,9 @@ protected Map createClassMemberVarExprs( fields.put(CLIENT_VAR_NAME, typeStore.get(ClassNames.getServiceClientClassName(service))); fields.put(CHANNEL_PROVIDER_VAR_NAME, FIXED_GRPC_TYPESTORE.get("LocalChannelProvider")); - return fields.entrySet().stream() + return fields + .entrySet() + .stream() .collect( Collectors.toMap( Map.Entry::getKey, @@ -163,7 +165,9 @@ protected MethodDefinition createStartStaticServerMethod( // Careful: Java 8 and 11 make different ordering choices if this set is not explicitly sorted. // Context: https://github.com/googleapis/gapic-generator-java/pull/750 for (Service mixinService : - context.mixinServices().stream() + context + .mixinServices() + .stream() .sorted((s1, s2) -> s2.name().compareTo(s1.name())) .collect(Collectors.toList())) { varInitExprs.add(serviceToVarInitExprFn.apply(mixinService)); @@ -1044,7 +1048,8 @@ protected List createStreamingRpcExceptionTestStatements( TryCatchStatement tryCatchBlock = TryCatchStatement.builder() .setTryBody( - tryBodyExprs.stream() + tryBodyExprs + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .addCatch( diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposer.java index a80feffcd5..a897f3003d 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposer.java @@ -51,7 +51,7 @@ protected ServiceStubSettingsClassComposer() { } private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( GaxGrpcProperties.class, GrpcTransportChannel.class, diff --git a/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java index 80801e31fe..c4077f119a 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java @@ -98,7 +98,10 @@ public GapicClass generate(ResourceName resourceName, GapicContext context) { TypeStore typeStore = createDynamicTypes(resourceName, tokenHierarchies); // Use the full name java.lang.Object if there is a proto message that is also named "Object". // Affects GCS. - if (context.messages().keySet().stream() + if (context + .messages() + .keySet() + .stream() .anyMatch(s -> s.equals("Object") || s.endsWith(".Object"))) { javaObjectReference = ConcreteReference.builder().setClazz(Object.class).setUseFullName(true).build(); @@ -166,7 +169,8 @@ private static List createImplementsTypes() { private static List createTemplateClassMembers( List> tokenHierarchies) { - return tokenHierarchies.stream() + return tokenHierarchies + .stream() .map( ts -> VariableExpr.withVariable( @@ -185,11 +189,13 @@ private static Map createPatternTokenClassMembers( List> tokenHierarchies) { // PubSub special-case handling - exclude _deleted-topic_. List> processedTokenHierarchies = - tokenHierarchies.stream() + tokenHierarchies + .stream() .filter(ts -> !ts.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); Set tokenSet = getTokenSet(processedTokenHierarchies); - return tokenSet.stream() + return tokenSet + .stream() .collect( Collectors.toMap( t -> t, @@ -262,11 +268,13 @@ private static List createClassStatements( v -> v.toBuilder().setIsDecl(true).setScope(ScopeNode.PRIVATE).setIsFinal(true).build(); // Special-cased PubSub handling. List> processedTokenHierarchies = - tokenHierarchies.stream() + tokenHierarchies + .stream() .filter(tokens -> !tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); memberVars.addAll( - getTokenSet(processedTokenHierarchies).stream() + getTokenSet(processedTokenHierarchies) + .stream() .map(t -> toFinalDeclFn.apply(patternTokenVarExprs.get(t))) .collect(Collectors.toList())); return memberVars.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList()); @@ -333,7 +341,8 @@ private static List createConstructorMethods( // Special-cased PubSub handling. List> processedTokenHierarchies = - tokenHierarchies.stream() + tokenHierarchies + .stream() .filter(tokens -> !tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); boolean hasDeletedTopicPattern = tokenHierarchies.size() > processedTokenHierarchies.size(); @@ -348,7 +357,8 @@ private static List createConstructorMethods( .setScope(ScopeNode.PROTECTED) .setReturnType(thisClassType) .setBody( - getTokenSet(processedTokenHierarchies).stream() + getTokenSet(processedTokenHierarchies) + .stream() .map(t -> ExprStatement.withExpr(assignTokenToNullExpr.apply(t))) .collect(Collectors.toList())) .build()); @@ -404,7 +414,8 @@ private static List createConstructorMethods( .setReturnType(thisClassType) .setArguments(Arrays.asList(builderArgExpr.toBuilder().setIsDecl(true).build())) .setBody( - bodyExprs.stream() + bodyExprs + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build()); @@ -443,7 +454,8 @@ private static List createConstructorMethods( .build()) .build()); specialCtorBodyExprs.addAll( - getTokenSet(processedTokenHierarchies).stream() + getTokenSet(processedTokenHierarchies) + .stream() .map(t -> assignTokenToNullExpr.apply(t)) .collect(Collectors.toList())); @@ -453,7 +465,8 @@ private static List createConstructorMethods( .setReturnType(thisClassType) .setArguments(Arrays.asList(fixedValueVarExpr.toBuilder().setIsDecl(true).build())) .setBody( - specialCtorBodyExprs.stream() + specialCtorBodyExprs + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build()); @@ -466,10 +479,12 @@ private static List createTokenGetterMethods( Map patternTokenVarExprs, List> tokenHierarchies) { // PubSub special-case handling. List> processedTokenHierarchies = - tokenHierarchies.stream() + tokenHierarchies + .stream() .filter(ts -> !ts.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); - return getTokenSet(processedTokenHierarchies).stream() + return getTokenSet(processedTokenHierarchies) + .stream() .map( t -> MethodDefinition.builder() @@ -657,7 +672,8 @@ private static List createOfOrFormatMethodHelper( .build(); } List methodArgs = - tokens.stream() + tokens + .stream() .map(t -> patternTokenVarExprs.get(t).toBuilder().setIsDecl(true).build()) .collect(Collectors.toList()); javaMethods.add( @@ -773,7 +789,9 @@ private static MethodDefinition createParseMethod( body.add(ExprStatement.withExpr(matchMapAssignExpr)); List ofMethodArgExprs = - tokenHierarchies.get(0).stream() + tokenHierarchies + .get(0) + .stream() .map( t -> MethodInvocationExpr.builder() @@ -835,7 +853,8 @@ private static MethodDefinition createParseMethod( MethodInvocationExpr.builder() .setMethodName(String.format(ofMethodNamePattern, concatToUpperCamelCaseName(tokens))) .setArguments( - tokens.stream() + tokens + .stream() .map( t -> MethodInvocationExpr.builder() @@ -852,7 +871,8 @@ private static MethodDefinition createParseMethod( ReturnExpr subReturnExpr = ReturnExpr.withExpr(ofMethodExpr); List ifStatements = - Arrays.asList(matchMapAssignExpr, subReturnExpr).stream() + Arrays.asList(matchMapAssignExpr, subReturnExpr) + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList()); if (i == 0) { @@ -1137,7 +1157,8 @@ private static MethodDefinition createGetFieldValuesMapMethod( // Special-cased PubSub handling. List> processedTokenHierarchies = - tokenHierarchies.stream() + tokenHierarchies + .stream() .filter(tokens -> !tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); @@ -1192,7 +1213,6 @@ private static MethodDefinition createGetFieldValuesMapMethod( .build(); // Outer if-block. - Expr thisExpr = ValueExpr.withValue(ThisObjectValue.withType(thisClassType)); IfStatement outerIfStatement = IfStatement.builder() .setConditionExpr(fieldValuesMapNullCheckExpr) @@ -1349,7 +1369,8 @@ private static MethodDefinition createEqualsMethod( // PubSub special-case handling - exclude _deleted-topic_. List> processedTokenHierarchies = - tokenHierarchies.stream() + tokenHierarchies + .stream() .filter(ts -> !ts.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); @@ -1447,7 +1468,8 @@ private static MethodDefinition createHashCodeMethod(List> tokenHie // PubSub special-case handling - exclude _deleted-topic_. List> processedTokenHierarchies = - tokenHierarchies.stream() + tokenHierarchies + .stream() .filter(ts -> !ts.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); @@ -1463,7 +1485,8 @@ private static MethodDefinition createHashCodeMethod(List> tokenHie } // Add the multiply and xor assignment operation exprs for tokens. Set tokenSet = getTokenSet(processedTokenHierarchies); - tokenSet.stream() + tokenSet + .stream() .forEach( token -> { VariableExpr tokenVarExpr = @@ -1538,7 +1561,8 @@ private static ClassDefinition createNestedBuilderClass( String className = isDefaultClass ? "Builder" : getBuilderTypeName(tokens); // Class member declarations. List classMemberVarExprs = - tokens.stream() + tokens + .stream() .map( t -> VariableExpr.withVariable( @@ -1548,7 +1572,8 @@ private static ClassDefinition createNestedBuilderClass( .build())) .collect(Collectors.toList()); List classMemberDecls = - classMemberVarExprs.stream() + classMemberVarExprs + .stream() .map( v -> ExprStatement.withExpr( @@ -1572,7 +1597,6 @@ private static ClassDefinition createNestedBuilderClass( for (int i = 0; i < tokens.size(); i++) { String token = tokens.get(i); String upperCamelTokenName = JavaStyle.toUpperCamelCase(token); - String lowerCamelTokenName = JavaStyle.toLowerCamelCase(token); VariableExpr currClassTokenVarExpr = classMemberVarExprs.get(i); // Getter. @@ -1648,8 +1672,6 @@ private static ClassDefinition createNestedBuilderClass( } for (int i = 0; i < tokens.size(); i++) { - String token = tokens.get(i); - String lowerCamelTokenName = JavaStyle.toLowerCamelCase(token); VariableExpr currClassTokenVarExpr = classMemberVarExprs.get(i).toBuilder().setExprReferenceExpr(thisExpr).build(); builderCtorBodyExprs.add( @@ -1669,7 +1691,8 @@ private static ClassDefinition createNestedBuilderClass( .setReturnType(thisClassType) .setArguments(outerClassVarExpr.toBuilder().setIsDecl(true).build()) .setBody( - builderCtorBodyExprs.stream() + builderCtorBodyExprs + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build(); @@ -1713,7 +1736,7 @@ private static ClassDefinition createNestedBuilderClass( } private static TypeStore createStaticTypes() { - List concreteClazzes = + List> concreteClazzes = Arrays.asList( ArrayList.class, BetaApi.class, @@ -1738,14 +1761,17 @@ private static TypeStore createDynamicTypes( // Special-cased PubSub handling. List> processedTokenHierarchies = - tokenHierarchies.stream() + tokenHierarchies + .stream() .filter(tokens -> !tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); if (processedTokenHierarchies.size() > 1) { typeStore.putAll( resourceName.pakkage(), - tokenHierarchies.subList(1, tokenHierarchies.size()).stream() + tokenHierarchies + .subList(1, tokenHierarchies.size()) + .stream() .map(ts -> getBuilderTypeName(ts)) .collect(Collectors.toList())); } @@ -1765,7 +1791,9 @@ private static Map createFixedClassMemberVariables() { memberVars.put( "pathTemplate", TypeNode.withReference(ConcreteReference.withClazz(PathTemplate.class))); memberVars.put("fixedValue", TypeNode.STRING); - return memberVars.entrySet().stream() + return memberVars + .entrySet() + .stream() .map(e -> Variable.builder().setName(e.getKey()).setType(e.getValue()).build()) .collect(Collectors.toMap(v -> v.identifier().name(), v -> VariableExpr.withVariable(v))); } @@ -1792,7 +1820,8 @@ private static TypeNode getBuilderType( @VisibleForTesting static Set getTokenSet(List> tokenHierarchy) { - return tokenHierarchy.stream() + return tokenHierarchy + .stream() .flatMap(tokens -> tokens.stream()) .collect(Collectors.toCollection(LinkedHashSet::new)); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java index ff927a3713..50ea1ad57e 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java @@ -592,6 +592,7 @@ private List getHttpMethodTypeExpr(Method protoMethod) { return Collections.singletonList(expr); } + @Override protected Optional getCallableCreatorMethodName(TypeNode callableVarExprType) { final String typeName = callableVarExprType.reference().name(); String streamName = "Unary"; diff --git a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java index 893777e057..a4a5426c4d 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java @@ -62,7 +62,6 @@ public class ServiceClientTestClassComposer extends AbstractServiceClientTestClassComposer { private static final String MOCK_SERVICE_VAR_NAME = "mockService"; - private static final String METHOD_DESCRIPTOR_NAME_PATTERN = "%sMethodDescriptor"; private static final ServiceClientTestClassComposer INSTANCE = new ServiceClientTestClassComposer(); @@ -102,14 +101,18 @@ protected Map createClassMemberVarExprs( fields.put( MOCK_SERVICE_VAR_NAME, FIXED_REST_TYPESTORE.get(MockHttpService.class.getSimpleName())); fields.put(CLIENT_VAR_NAME, typeStore.get(ClassNames.getServiceClientClassName(service))); - return fields.entrySet().stream() + return fields + .entrySet() + .stream() .collect(Collectors.toMap(e -> e.getKey(), e -> varExprFn.apply(e.getKey(), e.getValue()))); } @Override protected List createClassMemberFieldDecls( Map classMemberVarExprs) { - return classMemberVarExprs.values().stream() + return classMemberVarExprs + .values() + .stream() .map( v -> ExprStatement.withExpr( @@ -238,7 +241,8 @@ protected MethodDefinition createStartStaticServerMethod( .setThrowsExceptions(Arrays.asList(FIXED_TYPESTORE.get("IOException"))) .setIsStatic(true) .setBody( - Arrays.asList(initMockServiceExpr, initLocalSettingsExpr, initClientExpr).stream() + Arrays.asList(initMockServiceExpr, initLocalSettingsExpr, initClientExpr) + .stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build(); diff --git a/src/main/java/com/google/api/generator/gapic/composer/store/TypeStore.java b/src/main/java/com/google/api/generator/gapic/composer/store/TypeStore.java index 1a6c2e1c13..3794a306c0 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/store/TypeStore.java +++ b/src/main/java/com/google/api/generator/gapic/composer/store/TypeStore.java @@ -28,13 +28,14 @@ public class TypeStore { public TypeStore() {} - public TypeStore(List concreteClasses) { + public TypeStore(List> concreteClasses) { putConcreteClassses(concreteClasses); } - private void putConcreteClassses(List concreteClasses) { + private void putConcreteClassses(List> concreteClasses) { store.putAll( - concreteClasses.stream() + concreteClasses + .stream() .collect( Collectors.toMap( Class::getSimpleName, @@ -71,7 +72,7 @@ public void put( .build())); } - public void putAll(List concreteClasses) { + public void putAll(List> concreteClasses) { putConcreteClassses(concreteClasses); } @@ -87,7 +88,9 @@ public void putAll( public void putMessageTypes(String pakkage, Map messages) { store.putAll( - messages.entrySet().stream() + messages + .entrySet() + .stream() // Short-term hack for messages that have nested subtypes with colliding names. This // should work as long as there isn't heavy usage of fully-qualified nested subtypes in // general. A long-term fix would involve adding a custom type-store that handles diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/MethodSignatureParser.java b/src/main/java/com/google/api/generator/gapic/protoparser/MethodSignatureParser.java index 4d7259790a..d5ab3a6e4d 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/MethodSignatureParser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/MethodSignatureParser.java @@ -91,7 +91,9 @@ public static List> parseMethodSignatures( argumentNames.add(actualArgumentName); argumentNameToOverloads.put( actualArgumentName, - argumentTypes.entrySet().stream() + argumentTypes + .entrySet() + .stream() .map( e -> MethodArgument.builder() @@ -110,7 +112,8 @@ public static List> parseMethodSignatures( // Make the method signature order deterministic, which helps with unit testing and per-version // diffs. List> sortedMethodSignatures = - signatures.stream() + signatures + .stream() .sorted( (s1, s2) -> { // Sort by number of arguments first. @@ -208,7 +211,8 @@ private static Map parseTypeFromArgumentName( outputArgResourceNames.addAll(resourceNameArgs); typeToField.put(TypeNode.STRING, field); typeToField.putAll( - resourceNameArgs.stream() + resourceNameArgs + .stream() .collect( Collectors.toMap( r -> r.type(), @@ -221,7 +225,9 @@ private static Map parseTypeFromArgumentName( .build()))); // Only resource name helpers should have more than one entry. if (typeToField.size() > 1) { - typeToField.entrySet().stream() + typeToField + .entrySet() + .stream() .forEach( e -> { // Skip string-only variants or ResourceName generics. @@ -284,15 +290,4 @@ private static Map parseTypeFromArgumentName( argumentFieldPathAcc, outputArgResourceNames); } - - private static Map createPatternResourceNameMap( - Map resourceNames) { - Map patternsToResourceNames = new HashMap<>(); - for (ResourceName resourceName : resourceNames.values()) { - for (String pattern : resourceName.patterns()) { - patternsToResourceNames.put(pattern, resourceName); - } - } - return patternsToResourceNames; - } } diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/TypeParser.java b/src/main/java/com/google/api/generator/gapic/protoparser/TypeParser.java index 7a4542ee25..49b17d25db 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/TypeParser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/TypeParser.java @@ -37,8 +37,6 @@ import javax.annotation.Nonnull; public class TypeParser { - private static final String DOT = "."; - private static Reference REFERENCE_BYTE_STRING = ConcreteReference.withClazz(ByteString.class); private static TypeNode TYPE_NODE_BYTE_STRING = TypeNode.withReference(REFERENCE_BYTE_STRING); @@ -245,8 +243,6 @@ static Reference parseEnumReference(@Nonnull EnumDescriptor enumDescriptor) { @VisibleForTesting static TypeNode createListType(FieldDescriptor field) { - JavaType protoFieldType = field.getJavaType(); - Reference listReference = ConcreteReference.builder() .setClazz(List.class) @@ -259,7 +255,6 @@ static TypeNode createListType(FieldDescriptor field) { static TypeNode createMapType(FieldDescriptor field) { Preconditions.checkState( field.isMapField(), "createMapType can only be called on map-type fields"); - JavaType protoJavaType = field.getJavaType(); Descriptor type = field.getMessageType(); FieldDescriptor keyField = type.findFieldByName("key"); diff --git a/src/main/java/com/google/api/generator/util/Trie.java b/src/main/java/com/google/api/generator/util/Trie.java index 51a26180bc..4134b3f543 100644 --- a/src/main/java/com/google/api/generator/util/Trie.java +++ b/src/main/java/com/google/api/generator/util/Trie.java @@ -24,17 +24,17 @@ * A common-prefix trie. T represents the type of each "char" in a word (which is a T-typed list). */ public class Trie { - private class Node { - final T chr; + private class Node { + final U chr; // Maintain insertion order to enable deterministic test output. - Map> children = new LinkedHashMap<>(); + Map> children = new LinkedHashMap<>(); boolean isLeaf; Node() { chr = null; } - Node(T chr) { + Node(U chr) { this.chr = chr; } } @@ -42,18 +42,18 @@ private class Node { private Node root; public Trie() { - root = new Node(); + root = new Node<>(); } public void insert(List word) { Map> children = root.children; for (int i = 0; i < word.size(); i++) { T chr = word.get(i); - Node t; + Node t; if (children.containsKey(chr)) { t = children.get(chr); } else { - t = new Node(chr); + t = new Node<>(chr); children.put(chr, t); } children = t.children; @@ -65,7 +65,7 @@ public void insert(List word) { /** Returns true if the word is in the trie. */ public boolean search(List word) { - Node node = searchNode(word); + Node node = searchNode(word); return node != null && node.isLeaf; } @@ -119,11 +119,10 @@ private R dfsTraverseAndReduce( return parentPostprocFn.apply(node.chr, baseValue, leafReducedValue); } - private Node searchNode(List word) { + private Node searchNode(List word) { Map> children = root.children; - Node t = null; - for (int i = 0; i < word.size(); i++) { - T chr = word.get(i); + Node t = null; + for (T chr : word) { if (children.containsKey(chr)) { t = children.get(chr); children = t.children; From 3d20c0d36df3e346349d45e9978f37fc4ddfdcaa Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Mon, 13 Sep 2021 17:44:45 -0400 Subject: [PATCH 2/4] Format code --- .../engine/ast/MethodDefinition.java | 6 +- .../engine/writer/ImportWriterVisitor.java | 3 +- .../defaultvalue/DefaultValueComposer.java | 6 +- ...pcServiceCallableFactoryClassComposer.java | 30 +++---- .../grpc/MockServiceImplClassComposer.java | 12 +-- .../grpc/ServiceClientTestClassComposer.java | 11 +-- .../ResourceNameHelperClassComposer.java | 89 ++++++------------- .../rest/ServiceClientTestClassComposer.java | 11 +-- .../gapic/composer/store/TypeStore.java | 7 +- .../protoparser/MethodSignatureParser.java | 14 +-- 10 files changed, 58 insertions(+), 131 deletions(-) diff --git a/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java b/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java index 643e600e6d..4b65d14789 100644 --- a/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java +++ b/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java @@ -248,16 +248,14 @@ public MethodDefinition build() { ImmutableList processedAnnotations = annotations(); if (isOverride()) { processedAnnotations = - ImmutableList - .builder() + ImmutableList.builder() .addAll(annotations()) .add(AnnotationNode.OVERRIDE) .build(); } // Remove duplicates while maintaining insertion order. setAnnotations( - new LinkedHashSet<>(processedAnnotations) - .stream().collect(Collectors.toList())); + new LinkedHashSet<>(processedAnnotations).stream().collect(Collectors.toList())); MethodDefinition method = autoBuild(); diff --git a/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java b/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java index aec153d2f6..85274e34b9 100644 --- a/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java +++ b/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java @@ -123,8 +123,7 @@ public boolean collidesWithImport(String pakkage, String shortName) { updateShortNames(); } return importShortNames.contains(shortName) - && imports - .stream() + && imports.stream() .filter(s -> s.equals(String.format("%s.%s", pakkage, shortName))) .findFirst() .orElse("") diff --git a/src/main/java/com/google/api/generator/gapic/composer/defaultvalue/DefaultValueComposer.java b/src/main/java/com/google/api/generator/gapic/composer/defaultvalue/DefaultValueComposer.java index 0be270c1c8..f697c1b4a2 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/defaultvalue/DefaultValueComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/defaultvalue/DefaultValueComposer.java @@ -234,16 +234,14 @@ static Expr createDefaultValueResourceHelper( "of%sName", String.join( "", - patternPlaceholderTokens - .stream() + patternPlaceholderTokens.stream() .map(s -> JavaStyle.toUpperCamelCase(s)) .collect(Collectors.toList()))); } TypeNode resourceNameJavaType = resourceName.type(); List argExprs = - patternPlaceholderTokens - .stream() + patternPlaceholderTokens.stream() .map( s -> ValueExpr.withValue( diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceCallableFactoryClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceCallableFactoryClassComposer.java index d894d8b4f9..e953c1410a 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceCallableFactoryClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceCallableFactoryClassComposer.java @@ -68,13 +68,11 @@ protected MethodDefinition createUnaryCallableMethod(TypeStore typeStore) { /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -97,8 +95,7 @@ protected MethodDefinition createPagedCallableMethod(TypeStore typeStore) { /*grpcCallSettingsTemplateObjects=*/ Arrays.asList( requestTemplateName, responseTemplateName), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -118,8 +115,7 @@ protected MethodDefinition createOperationCallableMethod(TypeStore typeStore) { /*methodVariantName=*/ methodVariantName, /*grpcCallSettingsTemplateObjects=*/ Arrays.asList(requestTemplateName, OPERATION_TYPE), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -135,13 +131,11 @@ private MethodDefinition createBidiStreamingCallableMethod(TypeStore typeStore) /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ "Streaming", - /*callSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -157,13 +151,11 @@ private MethodDefinition createServerStreamingCallableMethod(TypeStore typeStore /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -179,13 +171,11 @@ private MethodDefinition createClientStreamingCallableMethod(TypeStore typeStore /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*grpcCallSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ "Streaming", - /*callSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList())); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceImplClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceImplClassComposer.java index f2c1edde1f..e16cc875f4 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceImplClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/MockServiceImplClassComposer.java @@ -98,10 +98,7 @@ public GapicClass generate(GapicContext context, Service service) { // Use the full name java.lang.Object if there is a proto message that is also named "Object". // Affects GCS. - if (context - .messages() - .keySet() - .stream() + if (context.messages().keySet().stream() .anyMatch(s -> s.equals("Object") || s.endsWith(".Object"))) { javaObjectReference = ConcreteReference.builder().setClazz(Object.class).setUseFullName(true).build(); @@ -274,9 +271,7 @@ private static MethodDefinition createResetMethod() { } private static List createProtoMethodOverrides(Service service) { - return service - .methods() - .stream() + return service.methods().stream() .filter(m -> !m.isMixin()) // Mixin APIs will get their own generated mocks. .map(m -> createGenericProtoMethodOverride(m)) .collect(Collectors.toList()); @@ -651,8 +646,7 @@ private static List createRequestResponseAssignStatements() { .setIsGeneric(true) .build()) .build(); - return Arrays.asList(assignRequestVarExpr, assignResponsesVarExpr) - .stream() + return Arrays.asList(assignRequestVarExpr, assignResponsesVarExpr).stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList()); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java index f2bba0459e..c55b3bd865 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java @@ -127,9 +127,7 @@ protected Map createClassMemberVarExprs( fields.put(CLIENT_VAR_NAME, typeStore.get(ClassNames.getServiceClientClassName(service))); fields.put(CHANNEL_PROVIDER_VAR_NAME, FIXED_GRPC_TYPESTORE.get("LocalChannelProvider")); - return fields - .entrySet() - .stream() + return fields.entrySet().stream() .collect( Collectors.toMap( Map.Entry::getKey, @@ -165,9 +163,7 @@ protected MethodDefinition createStartStaticServerMethod( // Careful: Java 8 and 11 make different ordering choices if this set is not explicitly sorted. // Context: https://github.com/googleapis/gapic-generator-java/pull/750 for (Service mixinService : - context - .mixinServices() - .stream() + context.mixinServices().stream() .sorted((s1, s2) -> s2.name().compareTo(s1.name())) .collect(Collectors.toList())) { varInitExprs.add(serviceToVarInitExprFn.apply(mixinService)); @@ -1048,8 +1044,7 @@ protected List createStreamingRpcExceptionTestStatements( TryCatchStatement tryCatchBlock = TryCatchStatement.builder() .setTryBody( - tryBodyExprs - .stream() + tryBodyExprs.stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .addCatch( diff --git a/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java index c4077f119a..683d7d1643 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java @@ -98,10 +98,7 @@ public GapicClass generate(ResourceName resourceName, GapicContext context) { TypeStore typeStore = createDynamicTypes(resourceName, tokenHierarchies); // Use the full name java.lang.Object if there is a proto message that is also named "Object". // Affects GCS. - if (context - .messages() - .keySet() - .stream() + if (context.messages().keySet().stream() .anyMatch(s -> s.equals("Object") || s.endsWith(".Object"))) { javaObjectReference = ConcreteReference.builder().setClazz(Object.class).setUseFullName(true).build(); @@ -169,8 +166,7 @@ private static List createImplementsTypes() { private static List createTemplateClassMembers( List> tokenHierarchies) { - return tokenHierarchies - .stream() + return tokenHierarchies.stream() .map( ts -> VariableExpr.withVariable( @@ -189,13 +185,11 @@ private static Map createPatternTokenClassMembers( List> tokenHierarchies) { // PubSub special-case handling - exclude _deleted-topic_. List> processedTokenHierarchies = - tokenHierarchies - .stream() + tokenHierarchies.stream() .filter(ts -> !ts.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); Set tokenSet = getTokenSet(processedTokenHierarchies); - return tokenSet - .stream() + return tokenSet.stream() .collect( Collectors.toMap( t -> t, @@ -268,13 +262,11 @@ private static List createClassStatements( v -> v.toBuilder().setIsDecl(true).setScope(ScopeNode.PRIVATE).setIsFinal(true).build(); // Special-cased PubSub handling. List> processedTokenHierarchies = - tokenHierarchies - .stream() + tokenHierarchies.stream() .filter(tokens -> !tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); memberVars.addAll( - getTokenSet(processedTokenHierarchies) - .stream() + getTokenSet(processedTokenHierarchies).stream() .map(t -> toFinalDeclFn.apply(patternTokenVarExprs.get(t))) .collect(Collectors.toList())); return memberVars.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList()); @@ -341,8 +333,7 @@ private static List createConstructorMethods( // Special-cased PubSub handling. List> processedTokenHierarchies = - tokenHierarchies - .stream() + tokenHierarchies.stream() .filter(tokens -> !tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); boolean hasDeletedTopicPattern = tokenHierarchies.size() > processedTokenHierarchies.size(); @@ -357,8 +348,7 @@ private static List createConstructorMethods( .setScope(ScopeNode.PROTECTED) .setReturnType(thisClassType) .setBody( - getTokenSet(processedTokenHierarchies) - .stream() + getTokenSet(processedTokenHierarchies).stream() .map(t -> ExprStatement.withExpr(assignTokenToNullExpr.apply(t))) .collect(Collectors.toList())) .build()); @@ -414,8 +404,7 @@ private static List createConstructorMethods( .setReturnType(thisClassType) .setArguments(Arrays.asList(builderArgExpr.toBuilder().setIsDecl(true).build())) .setBody( - bodyExprs - .stream() + bodyExprs.stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build()); @@ -454,8 +443,7 @@ private static List createConstructorMethods( .build()) .build()); specialCtorBodyExprs.addAll( - getTokenSet(processedTokenHierarchies) - .stream() + getTokenSet(processedTokenHierarchies).stream() .map(t -> assignTokenToNullExpr.apply(t)) .collect(Collectors.toList())); @@ -465,8 +453,7 @@ private static List createConstructorMethods( .setReturnType(thisClassType) .setArguments(Arrays.asList(fixedValueVarExpr.toBuilder().setIsDecl(true).build())) .setBody( - specialCtorBodyExprs - .stream() + specialCtorBodyExprs.stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build()); @@ -479,12 +466,10 @@ private static List createTokenGetterMethods( Map patternTokenVarExprs, List> tokenHierarchies) { // PubSub special-case handling. List> processedTokenHierarchies = - tokenHierarchies - .stream() + tokenHierarchies.stream() .filter(ts -> !ts.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); - return getTokenSet(processedTokenHierarchies) - .stream() + return getTokenSet(processedTokenHierarchies).stream() .map( t -> MethodDefinition.builder() @@ -672,8 +657,7 @@ private static List createOfOrFormatMethodHelper( .build(); } List methodArgs = - tokens - .stream() + tokens.stream() .map(t -> patternTokenVarExprs.get(t).toBuilder().setIsDecl(true).build()) .collect(Collectors.toList()); javaMethods.add( @@ -789,9 +773,7 @@ private static MethodDefinition createParseMethod( body.add(ExprStatement.withExpr(matchMapAssignExpr)); List ofMethodArgExprs = - tokenHierarchies - .get(0) - .stream() + tokenHierarchies.get(0).stream() .map( t -> MethodInvocationExpr.builder() @@ -853,8 +835,7 @@ private static MethodDefinition createParseMethod( MethodInvocationExpr.builder() .setMethodName(String.format(ofMethodNamePattern, concatToUpperCamelCaseName(tokens))) .setArguments( - tokens - .stream() + tokens.stream() .map( t -> MethodInvocationExpr.builder() @@ -871,8 +852,7 @@ private static MethodDefinition createParseMethod( ReturnExpr subReturnExpr = ReturnExpr.withExpr(ofMethodExpr); List ifStatements = - Arrays.asList(matchMapAssignExpr, subReturnExpr) - .stream() + Arrays.asList(matchMapAssignExpr, subReturnExpr).stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList()); if (i == 0) { @@ -1157,8 +1137,7 @@ private static MethodDefinition createGetFieldValuesMapMethod( // Special-cased PubSub handling. List> processedTokenHierarchies = - tokenHierarchies - .stream() + tokenHierarchies.stream() .filter(tokens -> !tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); @@ -1369,8 +1348,7 @@ private static MethodDefinition createEqualsMethod( // PubSub special-case handling - exclude _deleted-topic_. List> processedTokenHierarchies = - tokenHierarchies - .stream() + tokenHierarchies.stream() .filter(ts -> !ts.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); @@ -1468,8 +1446,7 @@ private static MethodDefinition createHashCodeMethod(List> tokenHie // PubSub special-case handling - exclude _deleted-topic_. List> processedTokenHierarchies = - tokenHierarchies - .stream() + tokenHierarchies.stream() .filter(ts -> !ts.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); @@ -1485,8 +1462,7 @@ private static MethodDefinition createHashCodeMethod(List> tokenHie } // Add the multiply and xor assignment operation exprs for tokens. Set tokenSet = getTokenSet(processedTokenHierarchies); - tokenSet - .stream() + tokenSet.stream() .forEach( token -> { VariableExpr tokenVarExpr = @@ -1561,8 +1537,7 @@ private static ClassDefinition createNestedBuilderClass( String className = isDefaultClass ? "Builder" : getBuilderTypeName(tokens); // Class member declarations. List classMemberVarExprs = - tokens - .stream() + tokens.stream() .map( t -> VariableExpr.withVariable( @@ -1572,8 +1547,7 @@ private static ClassDefinition createNestedBuilderClass( .build())) .collect(Collectors.toList()); List classMemberDecls = - classMemberVarExprs - .stream() + classMemberVarExprs.stream() .map( v -> ExprStatement.withExpr( @@ -1691,8 +1665,7 @@ private static ClassDefinition createNestedBuilderClass( .setReturnType(thisClassType) .setArguments(outerClassVarExpr.toBuilder().setIsDecl(true).build()) .setBody( - builderCtorBodyExprs - .stream() + builderCtorBodyExprs.stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build(); @@ -1761,17 +1734,14 @@ private static TypeStore createDynamicTypes( // Special-cased PubSub handling. List> processedTokenHierarchies = - tokenHierarchies - .stream() + tokenHierarchies.stream() .filter(tokens -> !tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) .collect(Collectors.toList()); if (processedTokenHierarchies.size() > 1) { typeStore.putAll( resourceName.pakkage(), - tokenHierarchies - .subList(1, tokenHierarchies.size()) - .stream() + tokenHierarchies.subList(1, tokenHierarchies.size()).stream() .map(ts -> getBuilderTypeName(ts)) .collect(Collectors.toList())); } @@ -1791,9 +1761,7 @@ private static Map createFixedClassMemberVariables() { memberVars.put( "pathTemplate", TypeNode.withReference(ConcreteReference.withClazz(PathTemplate.class))); memberVars.put("fixedValue", TypeNode.STRING); - return memberVars - .entrySet() - .stream() + return memberVars.entrySet().stream() .map(e -> Variable.builder().setName(e.getKey()).setType(e.getValue()).build()) .collect(Collectors.toMap(v -> v.identifier().name(), v -> VariableExpr.withVariable(v))); } @@ -1820,8 +1788,7 @@ private static TypeNode getBuilderType( @VisibleForTesting static Set getTokenSet(List> tokenHierarchy) { - return tokenHierarchy - .stream() + return tokenHierarchy.stream() .flatMap(tokens -> tokens.stream()) .collect(Collectors.toCollection(LinkedHashSet::new)); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java index a4a5426c4d..9df088bbd7 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java @@ -101,18 +101,14 @@ protected Map createClassMemberVarExprs( fields.put( MOCK_SERVICE_VAR_NAME, FIXED_REST_TYPESTORE.get(MockHttpService.class.getSimpleName())); fields.put(CLIENT_VAR_NAME, typeStore.get(ClassNames.getServiceClientClassName(service))); - return fields - .entrySet() - .stream() + return fields.entrySet().stream() .collect(Collectors.toMap(e -> e.getKey(), e -> varExprFn.apply(e.getKey(), e.getValue()))); } @Override protected List createClassMemberFieldDecls( Map classMemberVarExprs) { - return classMemberVarExprs - .values() - .stream() + return classMemberVarExprs.values().stream() .map( v -> ExprStatement.withExpr( @@ -241,8 +237,7 @@ protected MethodDefinition createStartStaticServerMethod( .setThrowsExceptions(Arrays.asList(FIXED_TYPESTORE.get("IOException"))) .setIsStatic(true) .setBody( - Arrays.asList(initMockServiceExpr, initLocalSettingsExpr, initClientExpr) - .stream() + Arrays.asList(initMockServiceExpr, initLocalSettingsExpr, initClientExpr).stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build(); diff --git a/src/main/java/com/google/api/generator/gapic/composer/store/TypeStore.java b/src/main/java/com/google/api/generator/gapic/composer/store/TypeStore.java index 3794a306c0..4113c3446b 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/store/TypeStore.java +++ b/src/main/java/com/google/api/generator/gapic/composer/store/TypeStore.java @@ -34,8 +34,7 @@ public TypeStore(List> concreteClasses) { private void putConcreteClassses(List> concreteClasses) { store.putAll( - concreteClasses - .stream() + concreteClasses.stream() .collect( Collectors.toMap( Class::getSimpleName, @@ -88,9 +87,7 @@ public void putAll( public void putMessageTypes(String pakkage, Map messages) { store.putAll( - messages - .entrySet() - .stream() + messages.entrySet().stream() // Short-term hack for messages that have nested subtypes with colliding names. This // should work as long as there isn't heavy usage of fully-qualified nested subtypes in // general. A long-term fix would involve adding a custom type-store that handles diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/MethodSignatureParser.java b/src/main/java/com/google/api/generator/gapic/protoparser/MethodSignatureParser.java index d5ab3a6e4d..9ca9825def 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/MethodSignatureParser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/MethodSignatureParser.java @@ -91,9 +91,7 @@ public static List> parseMethodSignatures( argumentNames.add(actualArgumentName); argumentNameToOverloads.put( actualArgumentName, - argumentTypes - .entrySet() - .stream() + argumentTypes.entrySet().stream() .map( e -> MethodArgument.builder() @@ -112,8 +110,7 @@ public static List> parseMethodSignatures( // Make the method signature order deterministic, which helps with unit testing and per-version // diffs. List> sortedMethodSignatures = - signatures - .stream() + signatures.stream() .sorted( (s1, s2) -> { // Sort by number of arguments first. @@ -211,8 +208,7 @@ private static Map parseTypeFromArgumentName( outputArgResourceNames.addAll(resourceNameArgs); typeToField.put(TypeNode.STRING, field); typeToField.putAll( - resourceNameArgs - .stream() + resourceNameArgs.stream() .collect( Collectors.toMap( r -> r.type(), @@ -225,9 +221,7 @@ private static Map parseTypeFromArgumentName( .build()))); // Only resource name helpers should have more than one entry. if (typeToField.size() > 1) { - typeToField - .entrySet() - .stream() + typeToField.entrySet().stream() .forEach( e -> { // Skip string-only variants or ResourceName generics. From 130e7b5eba7d2673e7f3045a50e04264d8248e2e Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Tue, 14 Sep 2021 18:09:25 -0400 Subject: [PATCH 3/4] Format style --- ...ctServiceCallableFactoryClassComposer.java | 18 +++---- .../AbstractServiceClientClassComposer.java | 48 ++++++------------- ...bstractServiceClientTestClassComposer.java | 19 ++------ .../AbstractServiceSettingsClassComposer.java | 8 +--- .../AbstractServiceStubClassComposer.java | 4 +- .../common/BatchingDescriptorComposer.java | 12 ++--- .../common/RetrySettingsComposer.java | 3 +- 7 files changed, 34 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceCallableFactoryClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceCallableFactoryClassComposer.java index cdcfee5ee4..09aa5948a0 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceCallableFactoryClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceCallableFactoryClassComposer.java @@ -131,13 +131,11 @@ protected MethodDefinition createUnaryCallableMethod(TypeStore typeStore) { /*returnCallableKindName=*/ methodVariantName, /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*transportCallSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*transportCallSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -159,8 +157,7 @@ protected MethodDefinition createPagedCallableMethod(TypeStore typeStore) { /*transportCallSettingsTemplateObjects=*/ Arrays.asList( requestTemplateName, responseTemplateName), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -176,13 +173,11 @@ protected MethodDefinition createBatchingCallableMethod(TypeStore typeStore) { /*returnCallableKindName=*/ "Unary", /*returnCallableTemplateNames=*/ methodTemplateNames, /*methodVariantName=*/ methodVariantName, - /*transportCallSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*transportCallSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList()), /*callSettingsVariantName=*/ methodVariantName, - /*callSettingsTemplateObjects=*/ methodTemplateNames - .stream() + /*callSettingsTemplateObjects=*/ methodTemplateNames.stream() .map(n -> (Object) n) .collect(Collectors.toList())); } @@ -274,8 +269,7 @@ protected MethodDefinition createGenericCallableMethod( .setMethodName(methodName) .setStaticReferenceType(getTransportContext().transportCallableFactoryType()) .setArguments( - arguments - .stream() + arguments.stream() .map(v -> v.toBuilder().setIsDecl(false).build()) .collect(Collectors.toList())) .setReturnType(returnType) diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java index 8acb2833a9..528d24d202 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java @@ -234,9 +234,7 @@ private List createFieldDeclarations( } } - return fieldNameToTypes - .entrySet() - .stream() + return fieldNameToTypes.entrySet().stream() .map( e -> { String varName = e.getKey(); @@ -416,8 +414,7 @@ private List createConstructorMethods( .setArguments(settingsVarExpr.toBuilder().setIsDecl(true).build()) .setThrowsExceptions(Arrays.asList(exceptionType)) .setBody( - ctorAssignmentExprs - .stream() + ctorAssignmentExprs.stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build()); @@ -450,8 +447,7 @@ private List createConstructorMethods( .setReturnType(thisClassType) .setArguments(stubVarExpr.toBuilder().setIsDecl(true).build()) .setBody( - ctorAssignmentExprs - .stream() + ctorAssignmentExprs.stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .build()); @@ -531,9 +527,7 @@ private List createGetterMethods( "A restructuring of stub classes is planned, so this may break in the future") .build(); - return methodNameToTypes - .entrySet() - .stream() + return methodNameToTypes.entrySet().stream() .map( e -> { String methodName = e.getKey(); @@ -592,8 +586,7 @@ private static List createServiceMethods( grpcRpcToJavaMethodMetadata .get(method.name()) .addAll( - generatedMethods - .stream() + generatedMethods.stream() .map(m -> javaMethodNameFn.apply(m)) .collect(Collectors.toList())); javaMethods.addAll(generatedMethods); @@ -664,8 +657,7 @@ private static List createMethodVariants( for (List signature : method.methodSignatures()) { // Get the argument list. List arguments = - signature - .stream() + signature.stream() .map( methodArg -> VariableExpr.builder() @@ -1056,8 +1048,7 @@ private static List createBackgroundResourceMethods( .setReturnType(TypeNode.BOOLEAN) .setName("awaitTermination") .setArguments( - arguments - .stream() + arguments.stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setThrowsExceptions(Arrays.asList(typeStore.get("InterruptedException"))) @@ -1239,8 +1230,7 @@ private static ClassDefinition createNestedRpcPagedResponseClass( .setReturnType(returnType) .setName("createAsync") .setArguments( - Arrays.asList(contextVarExpr, futureResponseVarExpr) - .stream() + Arrays.asList(contextVarExpr, futureResponseVarExpr).stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody(Arrays.asList(ExprStatement.withExpr(futurePageAssignExpr))) @@ -1341,8 +1331,7 @@ private static ClassDefinition createNestedRpcPageClass( .setScope(ScopeNode.PRIVATE) .setReturnType(classType) .setArguments( - Arrays.asList(contextVarExpr, responseVarExpr) - .stream() + Arrays.asList(contextVarExpr, responseVarExpr).stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody( @@ -1374,8 +1363,7 @@ private static ClassDefinition createNestedRpcPageClass( .setReturnType(classType) .setName("createPage") .setArguments( - Arrays.asList(contextVarExpr, responseVarExpr) - .stream() + Arrays.asList(contextVarExpr, responseVarExpr).stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr( @@ -1407,8 +1395,7 @@ private static ClassDefinition createNestedRpcPageClass( .setReturnType(futurePageType) .setName("createPageAsync") .setArguments( - Arrays.asList(contextVarExpr, futureResponseVarExpr) - .stream() + Arrays.asList(contextVarExpr, futureResponseVarExpr).stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr( @@ -1485,8 +1472,7 @@ private static ClassDefinition createNestedRpcFixedSizeCollectionClass( .setScope(ScopeNode.PRIVATE) .setReturnType(classType) .setArguments( - Arrays.asList(pagesVarExpr, collectionSizeVarExpr) - .stream() + Arrays.asList(pagesVarExpr, collectionSizeVarExpr).stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody( @@ -1523,8 +1509,7 @@ private static ClassDefinition createNestedRpcFixedSizeCollectionClass( .setReturnType(classType) .setName("createCollection") .setArguments( - Arrays.asList(pagesVarExpr, collectionSizeVarExpr) - .stream() + Arrays.asList(pagesVarExpr, collectionSizeVarExpr).stream() .map(e -> e.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr( @@ -1716,8 +1701,7 @@ private static void createVaporTypes(Service service, TypeStore typeStore) { } typeStore.putAll( service.pakkage(), - Arrays.asList("%sPagedResponse", "%sPage", "%sFixedSizeCollection") - .stream() + Arrays.asList("%sPagedResponse", "%sPage", "%sFixedSizeCollection").stream() .map(p -> String.format(p, JavaStyle.toUpperCamelCase(method.name()))) .collect(Collectors.toList()), true, @@ -1727,9 +1711,7 @@ private static void createVaporTypes(Service service, TypeStore typeStore) { // Pagination types. typeStore.putAll( service.pakkage(), - service - .methods() - .stream() + service.methods().stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java index c561dbd36a..1c49899d15 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java @@ -151,9 +151,7 @@ protected List createClassMemberFieldDecls( // Static fields go first. fieldDeclStatements.addAll( - classMemberVarExprs - .values() - .stream() + classMemberVarExprs.values().stream() .filter(v -> isMockVarExprFn.apply(v)) .map( v -> @@ -166,9 +164,7 @@ protected List createClassMemberFieldDecls( .collect(Collectors.toList())); fieldDeclStatements.addAll( - classMemberVarExprs - .values() - .stream() + classMemberVarExprs.values().stream() .filter(v -> !isMockVarExprFn.apply(v)) .map( v -> @@ -235,9 +231,7 @@ private List createTestMethods( String mixinServiceName = method.mixedInApiName().substring(dotIndex + 1); String mixinServiceProtoPackage = method.mixedInApiName().substring(0, dotIndex); Optional mixinServiceOpt = - context - .mixinServices() - .stream() + context.mixinServices().stream() .filter( s -> s.name().equals(mixinServiceName) @@ -830,8 +824,7 @@ protected List createRpcExceptionTestStatements( TryCatchStatement tryCatchBlock = TryCatchStatement.builder() .setTryBody( - tryBodyExprs - .stream() + tryBodyExprs.stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())) .addCatch(catchExceptionVarExpr.toBuilder().setIsDecl(true).build(), catchBody) @@ -891,9 +884,7 @@ private void addDynamicTypes(GapicContext context, Service service, TypeStore ty // Pagination types. typeStore.putAll( service.pakkage(), - service - .methods() - .stream() + service.methods().stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java index cea354f002..ccf15a1d64 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java @@ -133,9 +133,7 @@ private static List createClassHeaderComments( service.methods().isEmpty() ? Optional.empty() : Optional.of( - service - .methods() - .stream() + service.methods().stream() .filter(m -> m.stream() == Stream.NONE && !m.hasLro() && !m.isPaged()) .findFirst() .orElse(service.methods().get(0))); @@ -795,9 +793,7 @@ private static TypeStore createDynamicTypes(Service service) { // Pagination types. typeStore.putAll( service.pakkage(), - service - .methods() - .stream() + service.methods().stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java index 07c4bb26bc..3f80382bab 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java @@ -249,9 +249,7 @@ private static TypeStore createTypes(Service service, Map messa // Pagination types. typeStore.putAll( service.pakkage(), - service - .methods() - .stream() + service.methods().stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposer.java index cc47a8db20..dc96c7bc43 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposer.java @@ -230,8 +230,7 @@ private static MethodDefinition createGetRequestBuilderMethod( .setStatements( Arrays.asList( ExprStatement.withExpr( - builderVarExpr - .toBuilder() + builderVarExpr.toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .build()))) @@ -358,8 +357,7 @@ private static MethodDefinition createSplitResponseMethod( forIndexVarExpr, initValueExpr, subresponseCountVarExpr, - innerSubresponseForExprs - .stream() + innerSubresponseForExprs.stream() .map(e -> ExprStatement.withExpr(e)) .collect(Collectors.toList())); @@ -439,8 +437,7 @@ private static MethodDefinition createSplitResponseMethod( .setReturnType(TypeNode.VOID) .setName("splitResponse") .setArguments( - Arrays.asList(batchResponseVarExpr, batchVarExpr) - .stream() + Arrays.asList(batchResponseVarExpr, batchVarExpr).stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody(bodyStatements) @@ -489,8 +486,7 @@ private static MethodDefinition createSplitExceptionMethod(Method method) { .setReturnType(TypeNode.VOID) .setName("splitException") .setArguments( - Arrays.asList(throwableVarExpr, batchVarExpr) - .stream() + Arrays.asList(throwableVarExpr, batchVarExpr).stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setBody(Arrays.asList(forStatement)) diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java index 05dd660148..e5e4ad4195 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java @@ -474,8 +474,7 @@ private static Expr createRetryCodeDefinitionExpr( .setGenerics(Arrays.asList(STATUS_CODE_CODE_TYPE.reference())) .setMethodName("newArrayList") .setArguments( - retryCodes - .stream() + retryCodes.stream() .map(c -> toStatusCodeEnumRefExpr(c)) .collect(Collectors.toList())) .build(); From 65fc158e8e1170d275e3ff4db4bbdb8a382c059c Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Tue, 14 Sep 2021 18:13:57 -0400 Subject: [PATCH 4/4] Format style --- ...tractServiceStubSettingsClassComposer.java | 60 ++++++------------- ...ractTransportServiceStubClassComposer.java | 45 ++++---------- 2 files changed, 29 insertions(+), 76 deletions(-) diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java index d1cff00c91..7a38adba80 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java @@ -373,9 +373,7 @@ private static List createClassHeaderComments( service.methods().isEmpty() ? Optional.empty() : Optional.of( - service - .methods() - .stream() + service.methods().stream() .filter(m -> m.stream() == Stream.NONE && !m.hasLro() && !m.isPaged()) .findFirst() .orElse(service.methods().get(0))); @@ -451,8 +449,7 @@ private static List createClassStatements( // Assign DEFAULT_SERVICE_SCOPES. statements.add(SettingsCommentComposer.DEFAULT_SCOPES_COMMENT); VariableExpr defaultServiceScopesDeclVarExpr = - DEFAULT_SERVICE_SCOPES_VAR_EXPR - .toBuilder() + DEFAULT_SERVICE_SCOPES_VAR_EXPR.toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) @@ -489,9 +486,7 @@ private static List createClassStatements( // Declare settings members. statements.addAll( - methodSettingsMemberVarExprs - .values() - .stream() + methodSettingsMemberVarExprs.values().stream() .map( v -> exprToStatementFn.apply( @@ -644,8 +639,7 @@ private static Expr createPagedListDescriptorAssignExpr( .setReturnType(method.inputType()) .setName("injectToken") .setArguments( - Arrays.asList(payloadVarExpr, strTokenVarExpr) - .stream() + Arrays.asList(payloadVarExpr, strTokenVarExpr).stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr(returnExpr) @@ -674,8 +668,7 @@ private static Expr createPagedListDescriptorAssignExpr( .setReturnType(method.inputType()) .setName("injectPageSize") .setArguments( - Arrays.asList(payloadVarExpr, pageSizeVarExpr) - .stream() + Arrays.asList(payloadVarExpr, pageSizeVarExpr).stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setReturnExpr(returnExpr) @@ -806,8 +799,7 @@ private static Expr createPagedListDescriptorAssignExpr( // Declare and assign the variable. return AssignmentExpr.builder() .setVariableExpr( - pagedListDescVarExpr - .toBuilder() + pagedListDescVarExpr.toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) @@ -946,8 +938,7 @@ private static Expr createPagedListResponseFactoryAssignExpr( return AssignmentExpr.builder() .setVariableExpr( - pagedListResponseFactoryVarExpr - .toBuilder() + pagedListResponseFactoryVarExpr.toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) @@ -993,9 +984,7 @@ private static List createMethodSettingsGetterMethods( .setReturnExpr(e.getValue()) .build(); }; - return methodSettingsMemberVarExprs - .entrySet() - .stream() + return methodSettingsMemberVarExprs.entrySet().stream() .map(e -> varToMethodFn.apply(e)) .collect(Collectors.toList()); } @@ -1272,9 +1261,7 @@ private static MethodDefinition createClassConstructor( .build()) .build(); bodyStatements.addAll( - methodSettingsMemberVarExprs - .entrySet() - .stream() + methodSettingsMemberVarExprs.entrySet().stream() .map(e -> ExprStatement.withExpr(varInitExprFn.apply(e))) .collect(Collectors.toList())); @@ -1299,8 +1286,7 @@ private ClassDefinition createNestedBuilderClass( ConcreteReference.builder() .setClazz(StubSettings.Builder.class) .setGenerics( - Arrays.asList(typeStore.get(thisClassName), typeStore.get(className)) - .stream() + Arrays.asList(typeStore.get(thisClassName), typeStore.get(className)).stream() .map(t -> t.reference()) .collect(Collectors.toList())) .build()); @@ -1350,9 +1336,7 @@ private static List createNestedClassStatements( // Declare all the settings fields. exprs.addAll( - nestedMethodSettingsMemberVarExprs - .values() - .stream() + nestedMethodSettingsMemberVarExprs.values().stream() .map(v -> varDeclFn.apply(v)) .collect(Collectors.toList())); @@ -1550,9 +1534,7 @@ private static List createNestedClassConstructorMethods( ctorBodyStatements.add(EMPTY_LINE_STATEMENT); ctorBodyStatements.addAll( - nestedMethodSettingsMemberVarExprs - .entrySet() - .stream() + nestedMethodSettingsMemberVarExprs.entrySet().stream() .map( e -> { // TODO(miraleung): Extract this into another method. @@ -1661,9 +1643,7 @@ private static List createNestedClassConstructorMethods( .generics()) .setMethodName("of") .setArguments( - nestedMethodSettingsMemberVarExprs - .values() - .stream() + nestedMethodSettingsMemberVarExprs.values().stream() .filter( v -> isUnaryCallSettingsBuilderFn.apply(v.type()) @@ -1709,9 +1689,7 @@ private static List createNestedClassConstructorMethods( // TODO(cleanup): Technically this should actually use the outer class's Settings // members to avoid decoupling variable names. ctorBodyStatements.addAll( - nestedMethodSettingsMemberVarExprs - .values() - .stream() + nestedMethodSettingsMemberVarExprs.values().stream() .map( v -> ExprStatement.withExpr( @@ -2072,9 +2050,7 @@ private TypeStore createDynamicTypes(Service service, String pakkage) { // Pagination types. typeStore.putAll( service.pakkage(), - service - .methods() - .stream() + service.methods().stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), @@ -2126,8 +2102,7 @@ private static VariableExpr createNestedRetryableCodeDefinitionsVarExpr() { ConcreteReference.builder() .setClazz(ImmutableMap.class) .setGenerics( - Arrays.asList(TypeNode.STRING, immutableSetType) - .stream() + Arrays.asList(TypeNode.STRING, immutableSetType).stream() .map(t -> t.reference()) .collect(Collectors.toList())) .build()); @@ -2144,8 +2119,7 @@ private static VariableExpr createNestedRetryParamDefinitionsVarExpr() { ConcreteReference.builder() .setClazz(ImmutableMap.class) .setGenerics( - Arrays.asList(TypeNode.STRING, FIXED_TYPESTORE.get("RetrySettings")) - .stream() + Arrays.asList(TypeNode.STRING, FIXED_TYPESTORE.get("RetrySettings")).stream() .map(t -> t.reference()) .collect(Collectors.toList())) .build()); diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java index 8df5d94803..7137f4f1fb 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java @@ -254,9 +254,7 @@ protected List createClassStatements( protected List createMethodDescriptorVariableDecls( Service service, Map protoMethodNameToDescriptorVarExprs) { - return service - .methods() - .stream() + return service.methods().stream() .map( m -> createMethodDescriptorVariableDecl( @@ -266,9 +264,7 @@ protected List createMethodDescriptorVariableDecls( private static List createClassMemberFieldDeclarations( Map fieldNameToVarExprs) { - return fieldNameToVarExprs - .values() - .stream() + return fieldNameToVarExprs.values().stream() .map( v -> ExprStatement.withExpr( @@ -282,9 +278,7 @@ private static List createClassMemberFieldDeclarations( protected Map createProtoMethodNameToDescriptorClassMembers( Service service, Class descriptorClass) { - return service - .methods() - .stream() + return service.methods().stream() .collect( Collectors.toMap( Method::name, @@ -429,8 +423,7 @@ protected List createStaticCreatorMethods( .setReturnType(creatorMethodReturnType) .setName("create") .setArguments( - argList - .stream() + argList.stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setThrowsExceptions( @@ -570,9 +563,7 @@ protected List createConstructorMethods( secondCtorExprs.add( AssignmentExpr.builder() .setVariableExpr( - classMemberVarExprs - .get("callableFactory") - .toBuilder() + classMemberVarExprs.get("callableFactory").toBuilder() .setExprReferenceExpr(thisExpr) .build()) .setValueExpr(callableFactoryVarExpr) @@ -601,9 +592,7 @@ protected List createConstructorMethods( // Transport settings local variables. Map javaStyleMethodNameToTransportSettingsVarExprs = - service - .methods() - .stream() + service.methods().stream() .collect( Collectors.toMap( m -> JavaStyle.toLowerCamelCase(m.name()), @@ -626,9 +615,7 @@ protected List createConstructorMethods( .build()))); secondCtorExprs.addAll( - service - .methods() - .stream() + service.methods().stream() .map( m -> createTransportSettingsInitExpr( @@ -644,9 +631,7 @@ protected List createConstructorMethods( // Initialize Callable variables. secondCtorExprs.addAll( - callableClassMemberVarExprs - .entrySet() - .stream() + callableClassMemberVarExprs.entrySet().stream() .map( e -> createCallableInitExpr( @@ -796,9 +781,7 @@ protected Optional getCallableCreatorMethodName(TypeNode callableVarExpr private static List createCallableGetterMethods( Map callableClassMemberVarExprs) { - return callableClassMemberVarExprs - .entrySet() - .stream() + return callableClassMemberVarExprs.entrySet().stream() .map( e -> MethodDefinition.builder() @@ -930,8 +913,7 @@ private List createStubOverrideMethods( .apply("awaitTermination") .setReturnType(TypeNode.BOOLEAN) .setArguments( - awaitTerminationArgs - .stream() + awaitTerminationArgs.stream() .map(v -> v.toBuilder().setIsDecl(true).build()) .collect(Collectors.toList())) .setThrowsExceptions(Arrays.asList(FIXED_TYPESTORE.get("InterruptedException"))) @@ -940,8 +922,7 @@ private List createStubOverrideMethods( .setExprReferenceExpr(backgroundResourcesVarExpr) .setMethodName("awaitTermination") .setArguments( - awaitTerminationArgs - .stream() + awaitTerminationArgs.stream() .map(v -> (Expr) v) .collect(Collectors.toList())) .setReturnType(TypeNode.BOOLEAN) @@ -964,9 +945,7 @@ private TypeStore createDynamicTypes(Service service, String stubPakkage) { // Pagination types. typeStore.putAll( service.pakkage(), - service - .methods() - .stream() + service.methods().stream() .filter(m -> m.isPaged()) .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()),