Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix formatting and formatting validation logic #768

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/google/api/generator/gapic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ protected Statement createMethodDescriptorVariableDecl(
return ExprStatement.withExpr(
AssignmentExpr.builder()
.setVariableExpr(
methodDescriptorVarExpr.toBuilder()
methodDescriptorVarExpr
.toBuilder()
.setIsDecl(true)
.setScope(ScopeNode.PRIVATE)
.setIsStatic(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ private static List<Statement> 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)
Expand All @@ -224,7 +226,9 @@ private static List<Statement> createClassStatements(
}

memberVars.add(
FIXED_CLASS_VARS.get("fieldValuesMap").toBuilder()
FIXED_CLASS_VARS
.get("fieldValuesMap")
.toBuilder()
.setIsDecl(true)
.setScope(ScopeNode.PRIVATE)
.setIsVolatile(true)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1631,7 +1637,8 @@ private static ClassDefinition createNestedBuilderClass(
AssignmentExpr.builder()
.setVariableExpr(currClassTokenVarExpr)
.setValueExpr(
currClassTokenVarExpr.toBuilder()
currClassTokenVarExpr
.toBuilder()
.setExprReferenceExpr(outerClassVarExpr)
.build())
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -125,7 +124,8 @@ protected Statement createMethodDescriptorVariableDecl(
return ExprStatement.withExpr(
AssignmentExpr.builder()
.setVariableExpr(
methodDescriptorVarExpr.toBuilder()
methodDescriptorVarExpr
.toBuilder()
.setIsDecl(true)
.setScope(ScopeNode.PRIVATE)
.setIsStatic(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -247,8 +246,7 @@ protected MethodDefinition createStartStaticServerMethod(
protected MethodDefinition createStopServerMethod(
Service service, Map<String, VariableExpr> 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)
Expand Down Expand Up @@ -313,8 +311,7 @@ protected List<Statement> constructRpcTestCheckerLogic(
TypeNode.withReference(
ConcreteReference.builder()
.setClazz(List.class)
.setGenerics(
Arrays.asList(TypeNode.STRING.reference()))
.setGenerics(Arrays.asList(TypeNode.STRING.reference()))
.build()))
.setName("actualRequests")
.build());
Expand Down Expand Up @@ -353,10 +350,7 @@ protected List<Statement> 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()
Expand Down Expand Up @@ -429,7 +423,6 @@ protected MethodDefinition createStreamingRpcTestMethod(
return null;
}


@Override
protected MethodDefinition createRpcExceptionTestMethod(
Method method,
Expand Down Expand Up @@ -513,10 +506,10 @@ protected MethodDefinition createRpcExceptionTestMethod(

@Override
protected List<Statement> createStreamingRpcExceptionTestStatements(
Method method,
Map<String, VariableExpr> classMemberVarExprs,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes) {
Method method,
Map<String, VariableExpr> classMemberVarExprs,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes) {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/google/api/generator/gapic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Loading