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] feat: add settingsBuilder getters in ServiceStubSettings #246

Merged
merged 23 commits into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c71f061
feat: add factory var decl in ServiceStubSettings codegen
miraleung Aug 25, 2020
4919bba
fix: prevent duplicate MethodDefinition annotations
miraleung Aug 25, 2020
b77848e
feat: add descriptor fields to ServiceStubSettings codegen
miraleung Aug 25, 2020
861f142
feat: add starter Builder to ServiceStubSettings codegen
miraleung Aug 25, 2020
5f285df
feat: add settings.builder decls to ServiceStubSettings codegen
miraleung Aug 25, 2020
dbc5735
feat: add first nested ctors to ServiceStubSettings codegen
miraleung Aug 26, 2020
164c0b3
feat: add GapicServiceConfig DS and processing
miraleung Aug 26, 2020
3783203
feat: integrate GapicServiceConfig into GapicContext, Parser, Composer
miraleung Aug 26, 2020
3984eaa
feat: initial param block, RetrySettingsComposer, test
miraleung Aug 26, 2020
a0ef19e
fix!: refactor GapicRetrySettings
miraleung Aug 27, 2020
74dbcbb
fix: recognize 1. or .1 double patterns
miraleung Aug 27, 2020
34285db
feat: support BlockStatement in ClassDef stmts
miraleung Aug 27, 2020
2fc9d0e
feat: add params block to ServiceStubSettings codegen
miraleung Aug 27, 2020
f6727d8
feat: add codes def to ServiceStubSettings codegen
miraleung Aug 27, 2020
1c54ec1
feat: add initDefaults() to ServiceStubSettings codegen
miraleung Aug 27, 2020
c50a204
feat: add LRO to ServiceStubSettings.Builder.initDefaults
miraleung Aug 27, 2020
106528f
feat: add third ServiceStubSettings.Builder(settings) ctor
miraleung Aug 27, 2020
6858b33
feat: add createDefault() to ServiceStubSettings
miraleung Aug 27, 2020
0df98cb
feat: add ServiceStubSettings.applyToAllUnaryMethods method
miraleung Aug 27, 2020
5919b29
feat: add ServiceStubSettings.unaryMethodSettingsBuilders()
miraleung Aug 27, 2020
0e03f06
feat: add ServiceStubSettings.build()
miraleung Aug 27, 2020
f172ad1
feat: add settingsBuilder getters in ServiceStubSettings
miraleung Aug 27, 2020
625bd95
Merge branch 'master' into gp/g21
miraleung Aug 29, 2020
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 @@ -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