Skip to content

Commit

Permalink
[ggj][codegen] feat: add settingsBuilder getters in ServiceStubSettin…
Browse files Browse the repository at this point in the history
…gs (#246)

* feat: add factory var decl in ServiceStubSettings codegen

* fix: prevent duplicate MethodDefinition annotations

* feat: add descriptor fields to ServiceStubSettings codegen

* feat: add starter Builder to ServiceStubSettings codegen

* feat: add settings.builder decls to ServiceStubSettings codegen

* feat: add first nested ctors to ServiceStubSettings codegen

* feat: add GapicServiceConfig DS and processing

* feat: integrate GapicServiceConfig into GapicContext, Parser, Composer

* feat: initial param block, RetrySettingsComposer, test

* fix!: refactor GapicRetrySettings

* fix: recognize 1. or .1 double patterns

* feat: support BlockStatement in ClassDef stmts

* feat: add params block to ServiceStubSettings codegen

* feat: add codes def to ServiceStubSettings codegen

* feat: add initDefaults() to ServiceStubSettings codegen

* feat: add LRO to ServiceStubSettings.Builder.initDefaults

* feat: add third ServiceStubSettings.Builder(settings) ctor

* feat: add createDefault() to ServiceStubSettings

* feat: add ServiceStubSettings.applyToAllUnaryMethods method

* feat: add ServiceStubSettings.unaryMethodSettingsBuilders()

* feat: add ServiceStubSettings.build()

* feat: add settingsBuilder getters in ServiceStubSettings
  • Loading branch information
miraleung authored Aug 29, 2020
1 parent a099fc7 commit f99d0ac
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,8 @@ private static List<MethodDefinition> createNestedClassMethods(
nestedClassMethods.add(createNestedClassInitDefaultsMethod(service, serviceConfig, types));
nestedClassMethods.add(createNestedClassApplyToAllUnaryMethodsMethod(superType, types));
nestedClassMethods.add(createNestedClassUnaryMethodSettingsBuilderGetterMethod());

// TODO(miraleung): More methods.
nestedClassMethods.addAll(
createNestedClassSettingsBuilderGetterMethods(nestedMethodSettingsMemberVarExprs));
nestedClassMethods.add(createNestedClassBuildMethod(service, types));
return nestedClassMethods;
}
Expand Down Expand Up @@ -1556,6 +1556,43 @@ private static MethodDefinition createNestedClassUnaryMethodSettingsBuilderGette
.build();
}

private static List<MethodDefinition> createNestedClassSettingsBuilderGetterMethods(
Map<String, VariableExpr> nestedMethodSettingsMemberVarExprs) {
Reference operationCallSettingsBuilderRef =
ConcreteReference.withClazz(OperationCallSettings.Builder.class);
Function<TypeNode, Boolean> isOperationCallSettingsBuilderFn =
t ->
t.reference()
.copyAndSetGenerics(ImmutableList.of())
.equals(operationCallSettingsBuilderRef);
List<AnnotationNode> lroBetaAnnotations =
Arrays.asList(
AnnotationNode.builder()
.setType(STATIC_TYPES.get("BetaApi"))
.setDescription(
"The surface for use by generated code is not stable yet and may change in the"
+ " future.")
.build());

List<MethodDefinition> javaMethods = new ArrayList<>();
for (Map.Entry<String, VariableExpr> settingsVarEntry :
nestedMethodSettingsMemberVarExprs.entrySet()) {
String varName = settingsVarEntry.getKey();
VariableExpr settingsVarExpr = settingsVarEntry.getValue();
boolean isOperationCallSettings =
isOperationCallSettingsBuilderFn.apply(settingsVarExpr.type());
javaMethods.add(
MethodDefinition.builder()
.setAnnotations(isOperationCallSettings ? lroBetaAnnotations : ImmutableList.of())
.setScope(ScopeNode.PUBLIC)
.setReturnType(settingsVarExpr.type())
.setName(settingsVarExpr.variable().identifier().name())
.setReturnExpr(settingsVarExpr)
.build());
}
return javaMethods;
}

private static MethodDefinition createNestedClassBuildMethod(
Service service, Map<String, TypeNode> types) {
TypeNode outerClassType = types.get(getThisClassName(service.name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,52 @@ public void generateServiceClasses() {
+ " return unaryMethodSettingsBuilders;\n"
+ " }\n"
+ "\n"
+ " public UnaryCallSettings.Builder<EchoRequest, EchoResponse> echoSettings() {\n"
+ " return echoSettings;\n"
+ " }\n"
+ "\n"
+ " public ServerStreamingCallSettings.Builder<ExpandRequest, EchoResponse>"
+ " expandSettings() {\n"
+ " return expandSettings;\n"
+ " }\n"
+ "\n"
+ " public StreamingCallSettings.Builder<EchoRequest, EchoResponse> collectSettings()"
+ " {\n"
+ " return collectSettings;\n"
+ " }\n"
+ "\n"
+ " public StreamingCallSettings.Builder<EchoRequest, EchoResponse> chatSettings()"
+ " {\n"
+ " return chatSettings;\n"
+ " }\n"
+ "\n"
+ " public StreamingCallSettings.Builder<EchoRequest, EchoResponse>"
+ " chatAgainSettings() {\n"
+ " return chatAgainSettings;\n"
+ " }\n"
+ "\n"
+ " public PagedCallSettings.Builder<\n"
+ " PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse>\n"
+ " pagedExpandSettings() {\n"
+ " return pagedExpandSettings;\n"
+ " }\n"
+ "\n"
+ " public UnaryCallSettings.Builder<WaitRequest, Operation> waitSettings() {\n"
+ " return waitSettings;\n"
+ " }\n"
+ "\n"
+ " @BetaApi(\n"
+ " \"The surface for use by generated code is not stable yet and may change in"
+ " the future.\")\n"
+ " public OperationCallSettings.Builder<WaitRequest, WaitResponse, WaitMetadata>\n"
+ " waitOperationSettings() {\n"
+ " return waitOperationSettings;\n"
+ " }\n"
+ "\n"
+ " public UnaryCallSettings.Builder<BlockRequest, BlockResponse> blockSettings() {\n"
+ " return blockSettings;\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " public EchoStubSettings build() throws IOException {\n"
+ " return new EchoStubSettings(this);\n"
Expand Down

0 comments on commit f99d0ac

Please sign in to comment.