diff --git a/BUILD.bazel b/BUILD.bazel index 8823250fca..ca78e67014 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -11,11 +11,13 @@ JAVA_SRCS = [ "//src/main/java/com/google/api/generator:generator_files", "//src/main/java/com/google/api/generator/engine:engine_files", "//src/main/java/com/google/api/generator/gapic:gapic_files", + "//src/main/java/com/google/api/generator/util:util_files", ] TEST_SRCS = [ "//src/test/java/com/google/api/generator/engine:engine_files", "//src/test/java/com/google/api/generator/gapic:gapic_files", + "//src/test/java/com/google/api/generator/testutils:testutils_files", "//src/test/java/com/google/api/generator/util:util_files", "//src/test/java/com/google/api/generator/test/framework:framework_files", ] diff --git a/src/main/java/com/google/api/generator/gapic/BUILD.bazel b/src/main/java/com/google/api/generator/gapic/BUILD.bazel index 37a314ed0b..9f6eb8954e 100644 --- a/src/main/java/com/google/api/generator/gapic/BUILD.bazel +++ b/src/main/java/com/google/api/generator/gapic/BUILD.bazel @@ -7,8 +7,13 @@ filegroup( srcs = glob(["*.java"]) + [ "//src/main/java/com/google/api/generator/gapic/composer:composer_files", "//src/main/java/com/google/api/generator/gapic/composer/comment:comment_files", + "//src/main/java/com/google/api/generator/gapic/composer/defaultvalue:defaultvalue_files", + "//src/main/java/com/google/api/generator/gapic/composer/grpc:grpc_files", + "//src/main/java/com/google/api/generator/gapic/composer/resourcename:resourcename_files", + "//src/main/java/com/google/api/generator/gapic/composer/rest:rest_files", "//src/main/java/com/google/api/generator/gapic/composer/samplecode:samplecode_files", "//src/main/java/com/google/api/generator/gapic/composer/store:store_files", + "//src/main/java/com/google/api/generator/gapic/composer/utils:utils_files", "//src/main/java/com/google/api/generator/gapic/model:model_files", "//src/main/java/com/google/api/generator/gapic/protoparser:protoparser_files", "//src/main/java/com/google/api/generator/gapic/protowriter:protowriter_files", diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcContext.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcContext.java index 13623cfb5b..9a291669e2 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcContext.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcContext.java @@ -19,9 +19,9 @@ import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.generator.gapic.composer.common.TransportContext; import com.google.api.generator.gapic.composer.utils.ClassNames; import com.google.api.generator.gapic.model.Transport; -import com.google.api.generator.gapic.composer.common.TransportContext; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.longrunning.stub.OperationsStub; import io.grpc.MethodDescriptor; 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 dcb9e47e67..f1fbbf667f 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 @@ -153,7 +153,8 @@ protected Statement createMethodDescriptorVariableDecl( return ExprStatement.withExpr( AssignmentExpr.builder() .setVariableExpr( - methodDescriptorVarExpr.toBuilder() + methodDescriptorVarExpr + .toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) 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 b561541e9b..5ef204d741 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,8 @@ 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().anyMatch(s -> s.equals("Object") || s.endsWith(".Object"))) { + if (context.messages().keySet().stream() + .anyMatch(s -> s.equals("Object") || s.endsWith(".Object"))) { javaObjectReference = ConcreteReference.builder().setClazz(Object.class).setUseFullName(true).build(); } @@ -213,7 +214,8 @@ private static MethodDefinition createSetResponsesMethod(Service service) { Expr responseAssignExpr = AssignmentExpr.builder() .setVariableExpr( - responsesVarExpr.toBuilder() + responsesVarExpr + .toBuilder() .setExprReferenceExpr( ValueExpr.withValue(ThisObjectValue.withType(getThisClassType(service)))) .build()) diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposer.java index 9d4c9bc294..ff0e4ed23f 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposer.java @@ -17,8 +17,7 @@ import com.google.api.generator.gapic.composer.common.AbstractServiceSettingsClassComposer; public class ServiceSettingsClassComposer extends AbstractServiceSettingsClassComposer { - private static final ServiceSettingsClassComposer INSTANCE = - new ServiceSettingsClassComposer(); + private static final ServiceSettingsClassComposer INSTANCE = new ServiceSettingsClassComposer(); protected ServiceSettingsClassComposer() { super(GrpcContext.instance()); 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 8cad45faa0..ceba11ee62 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 @@ -28,8 +28,8 @@ import com.google.api.generator.engine.ast.ValueExpr; import com.google.api.generator.engine.ast.Variable; import com.google.api.generator.engine.ast.VariableExpr; -import com.google.api.generator.gapic.composer.common.AbstractServiceStubSettingsClassComposer; import com.google.api.generator.gapic.composer.comment.SettingsCommentComposer; +import com.google.api.generator.gapic.composer.common.AbstractServiceStubSettingsClassComposer; import com.google.api.generator.gapic.composer.store.TypeStore; import com.google.api.generator.gapic.composer.utils.ClassNames; import com.google.api.generator.gapic.model.Service; 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 28b65cd52e..c28da2e08a 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 @@ -200,7 +200,9 @@ private static List createClassStatements( // "projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}"); for (int i = 0; i < patterns.size(); i++) { VariableExpr varExpr = - templateFinalVarExprs.get(i).toBuilder() + templateFinalVarExprs + .get(i) + .toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) @@ -224,7 +226,9 @@ private static List createClassStatements( } memberVars.add( - FIXED_CLASS_VARS.get("fieldValuesMap").toBuilder() + FIXED_CLASS_VARS + .get("fieldValuesMap") + .toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsVolatile(true) @@ -1603,7 +1607,9 @@ private static ClassDefinition createNestedBuilderClass( .setStaticReferenceType(FIXED_TYPESTORE.get("Objects")) .setMethodName("equals") .setArguments( - FIXED_CLASS_VARS.get("pathTemplate").toBuilder() + FIXED_CLASS_VARS + .get("pathTemplate") + .toBuilder() .setExprReferenceExpr(outerClassVarExpr) .build(), templateFinalVarExpr) @@ -1631,7 +1637,8 @@ private static ClassDefinition createNestedBuilderClass( AssignmentExpr.builder() .setVariableExpr(currClassTokenVarExpr) .setValueExpr( - currClassTokenVarExpr.toBuilder() + currClassTokenVarExpr + .toBuilder() .setExprReferenceExpr(outerClassVarExpr) .build()) .build()); 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 8f0623c294..093ccdbab3 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 @@ -45,7 +45,6 @@ import com.google.api.generator.gapic.model.Method; import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.utils.JavaStyle; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; @@ -125,7 +124,8 @@ protected Statement createMethodDescriptorVariableDecl( return ExprStatement.withExpr( AssignmentExpr.builder() .setVariableExpr( - methodDescriptorVarExpr.toBuilder() + methodDescriptorVarExpr + .toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) 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 08cc0681e6..5eed17f8f2 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 @@ -229,8 +229,7 @@ protected MethodDefinition createStartStaticServerMethod( .build(); return MethodDefinition.builder() - .setAnnotations( - Arrays.asList(AnnotationNode.withType(FIXED_TYPESTORE.get("BeforeClass")))) + .setAnnotations(Arrays.asList(AnnotationNode.withType(FIXED_TYPESTORE.get("BeforeClass")))) .setScope(ScopeNode.PUBLIC) .setReturnType(TypeNode.VOID) .setName("startStaticServer") @@ -247,8 +246,7 @@ protected MethodDefinition createStartStaticServerMethod( protected MethodDefinition createStopServerMethod( Service service, Map classMemberVarExprs) { return MethodDefinition.builder() - .setAnnotations( - Arrays.asList(AnnotationNode.withType(FIXED_TYPESTORE.get("AfterClass")))) + .setAnnotations(Arrays.asList(AnnotationNode.withType(FIXED_TYPESTORE.get("AfterClass")))) .setScope(ScopeNode.PUBLIC) .setIsStatic(true) .setReturnType(TypeNode.VOID) @@ -313,8 +311,7 @@ protected List constructRpcTestCheckerLogic( TypeNode.withReference( ConcreteReference.builder() .setClazz(List.class) - .setGenerics( - Arrays.asList(TypeNode.STRING.reference())) + .setGenerics(Arrays.asList(TypeNode.STRING.reference())) .build())) .setName("actualRequests") .build()); @@ -353,10 +350,7 @@ protected List constructRpcTestCheckerLogic( VariableExpr apiClientHeaderKeyVarExpr = VariableExpr.withVariable( - Variable.builder() - .setType(TypeNode.STRING) - .setName("apiClientHeaderKey") - .build()); + Variable.builder().setType(TypeNode.STRING).setName("apiClientHeaderKey").build()); AssignmentExpr apiClientHeaderKeyAssignExpr = AssignmentExpr.builder() @@ -429,7 +423,6 @@ protected MethodDefinition createStreamingRpcTestMethod( return null; } - @Override protected MethodDefinition createRpcExceptionTestMethod( Method method, @@ -513,10 +506,10 @@ protected MethodDefinition createRpcExceptionTestMethod( @Override protected List createStreamingRpcExceptionTestStatements( - Method method, - Map classMemberVarExprs, - Map resourceNames, - Map messageTypes) { + Method method, + Map classMemberVarExprs, + Map resourceNames, + Map messageTypes) { return Collections.emptyList(); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceSettingsClassComposer.java index 53e27d577d..637dea043f 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceSettingsClassComposer.java @@ -17,8 +17,7 @@ import com.google.api.generator.gapic.composer.common.AbstractServiceSettingsClassComposer; public class ServiceSettingsClassComposer extends AbstractServiceSettingsClassComposer { - private static final ServiceSettingsClassComposer INSTANCE = - new ServiceSettingsClassComposer(); + private static final ServiceSettingsClassComposer INSTANCE = new ServiceSettingsClassComposer(); protected ServiceSettingsClassComposer() { super(RestContext.instance()); diff --git a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceStubSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceStubSettingsClassComposer.java index 8899a9faaa..9375399546 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceStubSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceStubSettingsClassComposer.java @@ -28,15 +28,14 @@ import com.google.api.generator.engine.ast.ValueExpr; import com.google.api.generator.engine.ast.Variable; import com.google.api.generator.engine.ast.VariableExpr; -import com.google.api.generator.gapic.composer.common.AbstractServiceStubSettingsClassComposer; import com.google.api.generator.gapic.composer.comment.SettingsCommentComposer; +import com.google.api.generator.gapic.composer.common.AbstractServiceStubSettingsClassComposer; import com.google.api.generator.gapic.composer.store.TypeStore; import com.google.api.generator.gapic.composer.utils.ClassNames; import com.google.api.generator.gapic.model.Service; import java.util.Arrays; -public class ServiceStubSettingsClassComposer extends - AbstractServiceStubSettingsClassComposer { +public class ServiceStubSettingsClassComposer extends AbstractServiceStubSettingsClassComposer { private static final ServiceStubSettingsClassComposer INSTANCE = new ServiceStubSettingsClassComposer(); @@ -67,7 +66,8 @@ protected MethodDefinition createDefaultTransportTransportProviderBuilderMethod( MethodInvocationExpr transportChannelProviderBuilderExpr = MethodInvocationExpr.builder() .setStaticReferenceType( - FIXED_REST_TYPESTORE.get(InstantiatingHttpJsonChannelProvider.class.getSimpleName())) + FIXED_REST_TYPESTORE.get( + InstantiatingHttpJsonChannelProvider.class.getSimpleName())) .setMethodName("newBuilder") .setReturnType(returnType) .build(); diff --git a/src/test/java/com/google/api/generator/gapic/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/BUILD.bazel index 7c614e8093..40de9b259f 100644 --- a/src/test/java/com/google/api/generator/gapic/BUILD.bazel +++ b/src/test/java/com/google/api/generator/gapic/BUILD.bazel @@ -4,6 +4,12 @@ filegroup( name = "gapic_files", srcs = [ "//src/test/java/com/google/api/generator/gapic/composer:composer_files", + "//src/test/java/com/google/api/generator/gapic/composer/defaultvalue:defaultvalue_files", + "//src/test/java/com/google/api/generator/gapic/composer/grpc:grpc_files", + "//src/test/java/com/google/api/generator/gapic/composer/resourcename:resourcename_files", + "//src/test/java/com/google/api/generator/gapic/composer/rest:rest_files", + "//src/test/java/com/google/api/generator/gapic/composer/samplecode:samplecode_files", + "//src/test/java/com/google/api/generator/gapic/composer/utils:utils_files", "//src/test/java/com/google/api/generator/gapic/model:model_files", "//src/test/java/com/google/api/generator/gapic/protoparser:protoparser_files", "//src/test/java/com/google/api/generator/gapic/utils:utils_files", diff --git a/src/test/java/com/google/api/generator/gapic/composer/constants/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/composer/constants/BUILD.bazel deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/test/java/com/google/api/generator/gapic/composer/grpc/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/composer/grpc/BUILD.bazel index dde9ad4053..14ac8deeba 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/grpc/BUILD.bazel +++ b/src/test/java/com/google/api/generator/gapic/composer/grpc/BUILD.bazel @@ -47,17 +47,10 @@ TEST_DEPS = [ ] filegroup( - name = "composer_files", + name = "grpc_files", srcs = glob(["*.java"]), ) -java_proto_library( - name = "pubsub_java_proto", - deps = [ - "@com_google_googleapis//google/pubsub/v1:pubsub_proto", - ], -) - java_proto_library( name = "common_resources_java_proto", deps = [ diff --git a/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposerTest.java index 8ccbc442ed..9bdb460f96 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposerTest.java @@ -62,8 +62,7 @@ public void generateGrpcServiceStubClass_httpBindings() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); Utils.saveCodegenToFile(this.getClass(), "GrpcTestingStub.golden", visitor.write()); - Path goldenFilePath = - Paths.get(Utils.getGoldenDir(this.getClass()), "GrpcTestingStub.golden"); + Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "GrpcTestingStub.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposerTest.java index cbb6bae23b..d2c1a50708 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposerTest.java @@ -18,7 +18,6 @@ import static junit.framework.Assert.assertEquals; import com.google.api.generator.engine.writer.JavaWriterVisitor; -import com.google.api.generator.gapic.composer.common.ServiceClientClassComposer; import com.google.api.generator.gapic.model.GapicClass; import com.google.api.generator.gapic.model.GapicContext; import com.google.api.generator.gapic.model.Service; @@ -38,8 +37,7 @@ public void generateClientTest_echoClient() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); Utils.saveCodegenToFile(this.getClass(), "EchoClientTest.golden", visitor.write()); - Path goldenFilePath = - Paths.get(Utils.getGoldenDir(this.getClass()), "EchoClientTest.golden"); + Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "EchoClientTest.golden"); assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java index 3a907c432f..b319bf8b50 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java @@ -67,8 +67,7 @@ public void generateServiceStubSettingsClasses_basic() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); Utils.saveCodegenToFile(this.getClass(), "EchoStubSettings.golden", visitor.write()); - Path goldenFilePath = - Paths.get(Utils.getGoldenDir(this.getClass()), "EchoStubSettings.golden"); + Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "EchoStubSettings.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameTokenizerTest.java b/src/test/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameTokenizerTest.java index 6e17170841..44ea5579bf 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameTokenizerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameTokenizerTest.java @@ -17,7 +17,6 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertEquals; -import com.google.api.generator.gapic.composer.resourcename.ResourceNameTokenizer; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.showcase.v1beta1.EchoOuterClass; diff --git a/src/test/java/com/google/api/generator/gapic/composer/rest/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/composer/rest/BUILD.bazel index da9ede10b2..c4532b3599 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/rest/BUILD.bazel +++ b/src/test/java/com/google/api/generator/gapic/composer/rest/BUILD.bazel @@ -47,17 +47,10 @@ TEST_DEPS = [ ] filegroup( - name = "composer_files", + name = "rest_files", srcs = glob(["*.java"]), ) -java_proto_library( - name = "pubsub_java_proto", - deps = [ - "@com_google_googleapis//google/pubsub/v1:pubsub_proto", - ], -) - java_proto_library( name = "common_resources_java_proto", deps = [ diff --git a/src/test/java/com/google/api/generator/gapic/composer/rest/RestTestProtoLoader.java b/src/test/java/com/google/api/generator/gapic/composer/rest/RestTestProtoLoader.java index b729cc17c0..c2e8ab8726 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/rest/RestTestProtoLoader.java +++ b/src/test/java/com/google/api/generator/gapic/composer/rest/RestTestProtoLoader.java @@ -49,30 +49,30 @@ public static RestTestProtoLoader instance() { } public GapicContext parseCompliance() { - FileDescriptor echoFileDescriptor = ComplianceOuterClass.getDescriptor(); - ServiceDescriptor echoServiceDescriptor = echoFileDescriptor.getServices().get(0); - assertEquals(echoServiceDescriptor.getName(), "Compliance"); + FileDescriptor echoFileDescriptor = ComplianceOuterClass.getDescriptor(); + ServiceDescriptor echoServiceDescriptor = echoFileDescriptor.getServices().get(0); + assertEquals(echoServiceDescriptor.getName(), "Compliance"); - Map messageTypes = Parser.parseMessages(echoFileDescriptor); - Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); - Set outputResourceNames = new HashSet<>(); - List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Map messageTypes = Parser.parseMessages(echoFileDescriptor); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + Set outputResourceNames = new HashSet<>(); + List services = + Parser.parseService( + echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); - String jsonFilename = "showcase_grpc_service_config.json"; - Path jsonPath = Paths.get(getTestFilesDirectory(), jsonFilename); - Optional configOpt = ServiceConfigParser.parse(jsonPath.toString()); - assertTrue(configOpt.isPresent()); - GapicServiceConfig config = configOpt.get(); + String jsonFilename = "showcase_grpc_service_config.json"; + Path jsonPath = Paths.get(getTestFilesDirectory(), jsonFilename); + Optional configOpt = ServiceConfigParser.parse(jsonPath.toString()); + assertTrue(configOpt.isPresent()); + GapicServiceConfig config = configOpt.get(); - return GapicContext.builder() - .setMessages(messageTypes) - .setResourceNames(resourceNames) - .setServices(services) - .setServiceConfig(config) - .setHelperResourceNames(outputResourceNames) - .setTransport(getTransport()) - .build(); - } + return GapicContext.builder() + .setMessages(messageTypes) + .setResourceNames(resourceNames) + .setServices(services) + .setServiceConfig(config) + .setHelperResourceNames(outputResourceNames) + .setTransport(getTransport()) + .build(); + } } diff --git a/src/test/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposerTest.java index 786344fcc1..028f4cca14 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposerTest.java @@ -36,7 +36,8 @@ public void generateClientTest_echoClient() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); Utils.saveCodegenToFile(this.getClass(), "ComplianceClientTest.golden", visitor.write()); - Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "ComplianceClientTest.golden"); + Path goldenFilePath = + Paths.get(Utils.getGoldenDir(this.getClass()), "ComplianceClientTest.golden"); assertCodeEquals(goldenFilePath, visitor.write()); } } diff --git a/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleCodeWriterTest.java b/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleCodeWriterTest.java index 4e5be8cd19..d9456c7dcf 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleCodeWriterTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleCodeWriterTest.java @@ -22,9 +22,9 @@ import com.google.api.generator.engine.ast.ExprStatement; import com.google.api.generator.engine.ast.MethodInvocationExpr; import com.google.api.generator.engine.ast.PrimitiveValue; -import com.google.api.generator.engine.ast.TypeNode; import com.google.api.generator.engine.ast.Statement; import com.google.api.generator.engine.ast.TryCatchStatement; +import com.google.api.generator.engine.ast.TypeNode; import com.google.api.generator.engine.ast.ValueExpr; import com.google.api.generator.engine.ast.Variable; import com.google.api.generator.engine.ast.VariableExpr; @@ -34,47 +34,49 @@ public class SampleCodeWriterTest { @Test public void writeSampleCode_statements() { - TypeNode settingType = TypeNode.withReference(ConcreteReference.withClazz(ClientSettings.class)); + TypeNode settingType = + TypeNode.withReference(ConcreteReference.withClazz(ClientSettings.class)); Variable aVar = Variable.builder().setName("clientSettings").setType(settingType).build(); VariableExpr aVarExpr = VariableExpr.withVariable(aVar); - MethodInvocationExpr aValueExpr = MethodInvocationExpr.builder() - .setExprReferenceExpr(MethodInvocationExpr.builder() - .setMethodName("newBuilder") - .setStaticReferenceType(settingType) - .build()) - .setReturnType(settingType) - .setMethodName("build") - .build(); - AssignmentExpr assignmentExpr = AssignmentExpr.builder() - .setVariableExpr(aVarExpr.toBuilder().setIsDecl(true).build()) - .setValueExpr(aValueExpr) - .build(); - Statement sampleStatement = TryCatchStatement.builder() - .setTryResourceExpr(createAssignmentExpr("aBool", "false", TypeNode.BOOLEAN)) - .setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr("x", "3", TypeNode.INT)))) - .setIsSampleCode(true) - .build(); - String result = SampleCodeWriter.write( - ExprStatement.withExpr(assignmentExpr), - sampleStatement); - String expected = "ClientSettings clientSettings = ClientSettings.newBuilder().build();\n" - + "try (boolean aBool = false) {\n" - + " int x = 3;\n" - + "}"; + MethodInvocationExpr aValueExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr( + MethodInvocationExpr.builder() + .setMethodName("newBuilder") + .setStaticReferenceType(settingType) + .build()) + .setReturnType(settingType) + .setMethodName("build") + .build(); + AssignmentExpr assignmentExpr = + AssignmentExpr.builder() + .setVariableExpr(aVarExpr.toBuilder().setIsDecl(true).build()) + .setValueExpr(aValueExpr) + .build(); + Statement sampleStatement = + TryCatchStatement.builder() + .setTryResourceExpr(createAssignmentExpr("aBool", "false", TypeNode.BOOLEAN)) + .setTryBody( + Arrays.asList(ExprStatement.withExpr(createAssignmentExpr("x", "3", TypeNode.INT)))) + .setIsSampleCode(true) + .build(); + String result = SampleCodeWriter.write(ExprStatement.withExpr(assignmentExpr), sampleStatement); + String expected = + "ClientSettings clientSettings = ClientSettings.newBuilder().build();\n" + + "try (boolean aBool = false) {\n" + + " int x = 3;\n" + + "}"; assertEquals(expected, result); } private AssignmentExpr createAssignmentExpr(String varName, String varValue, TypeNode type) { Variable variable = Variable.builder().setName(varName).setType(type).build(); VariableExpr variableExpr = - VariableExpr.builder() - .setVariable(variable) - .setIsDecl(true) - .build(); + VariableExpr.builder().setVariable(variable).setIsDecl(true).build(); return AssignmentExpr.builder() .setVariableExpr(variableExpr) - .setValueExpr(ValueExpr.withValue(PrimitiveValue.builder().setType(type).setValue(varValue).build())) + .setValueExpr( + ValueExpr.withValue(PrimitiveValue.builder().setType(type).setValue(varValue).build())) .build(); } - } diff --git a/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleCodeComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleCodeComposerTest.java index b7438e4732..b00985942f 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleCodeComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleCodeComposerTest.java @@ -25,56 +25,68 @@ public class SettingsSampleCodeComposerTest { @Test public void composeSettingsSampleCode_noMethods() { - TypeNode classType = TypeNode.withReference(VaporReference.builder() - .setName("EchoSettings") - .setPakkage("com.google.showcase.v1beta1") - .build()); - Optional results = SettingsSampleCodeComposer.composeSampleCode(Optional.empty(), "EchoSettings", classType); + TypeNode classType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoSettings") + .setPakkage("com.google.showcase.v1beta1") + .build()); + Optional results = + SettingsSampleCodeComposer.composeSampleCode(Optional.empty(), "EchoSettings", classType); assertEquals(results, Optional.empty()); } @Test public void composeSettingsSampleCode_serviceSettingsClass() { - TypeNode classType = TypeNode.withReference(VaporReference.builder() - .setName("EchoSettings") - .setPakkage("com.google.showcase.v1beta1") - .build()); - Optional results = SettingsSampleCodeComposer.composeSampleCode(Optional.of("Echo"), "EchoSettings", classType); - String expected = LineFormatter.lines( - "EchoSettings.Builder echoSettingsBuilder = EchoSettings.newBuilder();\n", - "echoSettingsBuilder\n", - " .echoSettings()\n", - " .setRetrySettings(\n", - " echoSettingsBuilder\n", - " .echoSettings()\n", - " .getRetrySettings()\n", - " .toBuilder()\n", - " .setTotalTimeout(Duration.ofSeconds(30))\n", - " .build());\n", - "EchoSettings echoSettings = echoSettingsBuilder.build();"); + TypeNode classType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoSettings") + .setPakkage("com.google.showcase.v1beta1") + .build()); + Optional results = + SettingsSampleCodeComposer.composeSampleCode( + Optional.of("Echo"), "EchoSettings", classType); + String expected = + LineFormatter.lines( + "EchoSettings.Builder echoSettingsBuilder = EchoSettings.newBuilder();\n", + "echoSettingsBuilder\n", + " .echoSettings()\n", + " .setRetrySettings(\n", + " echoSettingsBuilder\n", + " .echoSettings()\n", + " .getRetrySettings()\n", + " .toBuilder()\n", + " .setTotalTimeout(Duration.ofSeconds(30))\n", + " .build());\n", + "EchoSettings echoSettings = echoSettingsBuilder.build();"); assertEquals(results.get(), expected); } @Test public void composeSettingsSampleCode_serviceStubClass() { - TypeNode classType = TypeNode.withReference(VaporReference.builder() - .setName("EchoStubSettings") - .setPakkage("com.google.showcase.v1beta1") - .build()); - Optional results = SettingsSampleCodeComposer.composeSampleCode(Optional.of("Echo"), "EchoSettings", classType); - String expected = LineFormatter.lines( - "EchoStubSettings.Builder echoSettingsBuilder = EchoStubSettings.newBuilder();\n", - "echoSettingsBuilder\n", - " .echoSettings()\n", - " .setRetrySettings(\n", - " echoSettingsBuilder\n", - " .echoSettings()\n", - " .getRetrySettings()\n", - " .toBuilder()\n", - " .setTotalTimeout(Duration.ofSeconds(30))\n", - " .build());\n", - "EchoStubSettings echoSettings = echoSettingsBuilder.build();"); + TypeNode classType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoStubSettings") + .setPakkage("com.google.showcase.v1beta1") + .build()); + Optional results = + SettingsSampleCodeComposer.composeSampleCode( + Optional.of("Echo"), "EchoSettings", classType); + String expected = + LineFormatter.lines( + "EchoStubSettings.Builder echoSettingsBuilder = EchoStubSettings.newBuilder();\n", + "echoSettingsBuilder\n", + " .echoSettings()\n", + " .setRetrySettings(\n", + " echoSettingsBuilder\n", + " .echoSettings()\n", + " .getRetrySettings()\n", + " .toBuilder()\n", + " .setTotalTimeout(Duration.ofSeconds(30))\n", + " .build());\n", + "EchoStubSettings echoSettings = echoSettingsBuilder.build();"); assertEquals(results.get(), expected); } - }