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

[ggj][codegen] fix: ServiceClient member variables and method calls #315

Merged
merged 15 commits into from
Sep 19, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Generated;
Expand Down Expand Up @@ -134,7 +135,7 @@ private static List<MethodDefinition> createClassMethods(
boolean hasLroClient) {
List<MethodDefinition> methods = new ArrayList<>();
methods.addAll(createStaticCreatorMethods(service, types));
methods.addAll(createConstructorMethods(service, types));
methods.addAll(createConstructorMethods(service, types, hasLroClient));
methods.addAll(createGetterMethods(service, types, hasLroClient));
methods.addAll(createServiceMethods(service, messageTypes, types));
methods.addAll(createBackgroundResourceMethods(service, types));
Expand Down Expand Up @@ -274,7 +275,7 @@ private static List<MethodDefinition> createStaticCreatorMethods(
}

private static List<MethodDefinition> createConstructorMethods(
Service service, Map<String, TypeNode> types) {
Service service, Map<String, TypeNode> types, boolean hasLroClient) {
List<MethodDefinition> methods = new ArrayList<>();
String thisClientName = String.format("%sClient", service.name());
String settingsName = String.format("%sSettings", service.name());
Expand Down Expand Up @@ -342,7 +343,9 @@ private static List<MethodDefinition> createConstructorMethods(
.setReturnType(operationsClientVarExpr.type())
.build())
.build();
ctorAssignmentExprs.add(operationsClientAssignExpr);
if (hasLroClient) {
ctorAssignmentExprs.add(operationsClientAssignExpr);
}

methods.add(
MethodDefinition.constructorBuilder()
Expand Down Expand Up @@ -370,7 +373,9 @@ private static List<MethodDefinition> createConstructorMethods(
.setVariableExpr(stubVarExpr.toBuilder().setExprReferenceExpr(thisExpr).build())
.setValueExpr(stubVarExpr)
.build());
ctorAssignmentExprs.add(operationsClientAssignExpr);
if (hasLroClient) {
ctorAssignmentExprs.add(operationsClientAssignExpr);
}
AnnotationNode betaAnnotation =
AnnotationNode.builder()
.setType(types.get("BetaApi"))
Expand Down Expand Up @@ -536,8 +541,8 @@ private static List<MethodDefinition> createMethodVariants(
if (argument.isResourceNameHelper()) {
MethodInvocationExpr isNullCheckExpr =
MethodInvocationExpr.builder()
.setStaticReferenceType(types.get("Strings"))
.setMethodName("isNullOrEmpty")
.setStaticReferenceType(types.get("Objects"))
.setMethodName("isNull")
.setArguments(Arrays.asList(argVarExpr))
.setReturnType(TypeNode.BOOLEAN)
.build();
Expand Down Expand Up @@ -897,6 +902,7 @@ private static Map<String, TypeNode> createConcreteTypes() {
InterruptedException.class,
IOException.class,
MoreExecutors.class,
Objects.class,
Operation.class,
OperationFuture.class,
OperationCallable.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public void generateServiceClasses() {
+ "import com.google.api.gax.rpc.ServerStreamingCallable;\n"
+ "import com.google.api.gax.rpc.UnaryCallable;\n"
+ "import com.google.api.resourcenames.ResourceName;\n"
+ "import com.google.common.base.Strings;\n"
+ "import com.google.longrunning.Operation;\n"
+ "import com.google.longrunning.OperationsClient;\n"
+ "import com.google.rpc.Status;\n"
+ "import com.google.showcase.v1beta1.stub.EchoStub;\n"
+ "import com.google.showcase.v1beta1.stub.EchoStubSettings;\n"
+ "import java.io.IOException;\n"
+ "import java.util.Objects;\n"
+ "import java.util.concurrent.TimeUnit;\n"
+ "import javax.annotation.Generated;\n"
+ "\n"
Expand Down Expand Up @@ -213,7 +213,7 @@ public void generateServiceClasses() {
+ " public final EchoResponse echo(ResourceName parent) {\n"
+ " EchoRequest request =\n"
+ " EchoRequest.newBuilder()\n"
+ " .setParent(Strings.isNullOrEmpty(parent) ? null : parent.toString())\n"
+ " .setParent(Objects.isNull(parent) ? null : parent.toString())\n"
+ " .build();\n"
+ " return echo(request);\n"
+ " }\n"
Expand All @@ -239,9 +239,8 @@ public void generateServiceClasses() {
+ " */\n"
+ " public final EchoResponse echo(FoobarName name) {\n"
+ " EchoRequest request =\n"
+ " EchoRequest.newBuilder()\n"
+ " .setName(Strings.isNullOrEmpty(name) ? null : name.toString())\n"
+ " .build();\n"
+ " EchoRequest.newBuilder().setName(Objects.isNull(name) ? null :"
+ " name.toString()).build();\n"
+ " return echo(request);\n"
+ " }\n"
+ "\n"
Expand Down