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 third ServiceStubSettings.Builder(settings) ctor #241

Merged
merged 18 commits into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 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
46b0880
Merge branch 'master' into gp/g16
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 @@ -610,7 +610,6 @@ private static Map<String, TypeNode> createStaticTypes() {
RetrySettings.class,
StatusCode.class,
UnaryCallSettings.class);

return concreteClazzes.stream()
.collect(
Collectors.toMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ private static List<MethodDefinition> createNestedClassMethods(
Map<String, TypeNode> types) {
List<MethodDefinition> nestedClassMethods = new ArrayList<>();
nestedClassMethods.addAll(
createNestedClassConstructorMethods(nestedMethodSettingsMemberVarExprs, types));
createNestedClassConstructorMethods(service, nestedMethodSettingsMemberVarExprs, types));
nestedClassMethods.add(createNestedClassInitDefaultsMethod(service, serviceConfig, types));

// TODO(miraleung): More methods.
Expand Down Expand Up @@ -1220,7 +1220,10 @@ private static MethodDefinition createNestedClassInitDefaultsMethod(
}

private static List<MethodDefinition> createNestedClassConstructorMethods(
Map<String, VariableExpr> nestedMethodSettingsMemberVarExprs, Map<String, TypeNode> types) {
Service service,
Map<String, VariableExpr> nestedMethodSettingsMemberVarExprs,
Map<String, TypeNode> types) {

TypeNode builderType = types.get(NESTED_BUILDER_CLASS_NAME);

List<MethodDefinition> ctorMethods = new ArrayList<>();
Expand Down Expand Up @@ -1324,7 +1327,7 @@ private static List<MethodDefinition> createNestedClassConstructorMethods(
})
.collect(Collectors.toList()));

ctorBodyExprs.add(
Expr unaryMethodSettingsBuildersAssignExpr =
AssignmentExpr.builder()
.setVariableExpr(NESTED_UNARY_METHOD_SETTINGS_BUILDERS_VAR_EXPR)
.setValueExpr(
Expand All @@ -1345,7 +1348,8 @@ private static List<MethodDefinition> createNestedClassConstructorMethods(
.collect(Collectors.toList()))
.setReturnType(NESTED_UNARY_METHOD_SETTINGS_BUILDERS_VAR_EXPR.type())
.build())
.build());
.build();
ctorBodyExprs.add(unaryMethodSettingsBuildersAssignExpr);

ctorBodyExprs.add(
MethodInvocationExpr.builder()
Expand All @@ -1364,6 +1368,50 @@ private static List<MethodDefinition> createNestedClassConstructorMethods(
.collect(Collectors.toList()))
.build());

// Third constructor that takes a ServivceStubSettings.
TypeNode outerSettingsType = types.get(getThisClassName(service.name()));
VariableExpr settingsVarExpr =
VariableExpr.withVariable(
Variable.builder().setType(outerSettingsType).setName("settings").build());
ctorBodyExprs = new ArrayList<>();
ctorBodyExprs.add(
ReferenceConstructorExpr.superBuilder()
.setType(builderType)
.setArguments(settingsVarExpr)
.build());
// TODO(cleanup): Technically this should actually use the outer class's <method>Settings
// members to avoid decoupling variable names.
ctorBodyExprs.addAll(
nestedMethodSettingsMemberVarExprs.values().stream()
.map(
v ->
AssignmentExpr.builder()
.setVariableExpr(v)
.setValueExpr(
MethodInvocationExpr.builder()
.setExprReferenceExpr(
VariableExpr.builder()
.setExprReferenceExpr(settingsVarExpr)
.setVariable(v.variable())
.build())
.setMethodName("toBuilder")
.setReturnType(v.type())
.build())
.build())
.collect(Collectors.toList()));
ctorBodyExprs.add(unaryMethodSettingsBuildersAssignExpr);

ctorMethods.add(
MethodDefinition.constructorBuilder()
.setScope(ScopeNode.PROTECTED)
.setReturnType(builderType)
.setArguments(settingsVarExpr.toBuilder().setIsDecl(true).build())
.setBody(
ctorBodyExprs.stream()
.map(e -> ExprStatement.withExpr(e))
.collect(Collectors.toList()))
.build());

return ctorMethods;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,22 @@ public void generateServiceClasses() {
+ " initDefaults(this);\n"
+ " }\n"
+ "\n"
+ " protected Builder(EchoStubSettings settings) {\n"
+ " super(settings);\n"
+ " echoSettings = settings.echoSettings.toBuilder();\n"
+ " expandSettings = settings.expandSettings.toBuilder();\n"
+ " collectSettings = settings.collectSettings.toBuilder();\n"
+ " chatSettings = settings.chatSettings.toBuilder();\n"
+ " chatAgainSettings = settings.chatAgainSettings.toBuilder();\n"
+ " pagedExpandSettings = settings.pagedExpandSettings.toBuilder();\n"
+ " waitSettings = settings.waitSettings.toBuilder();\n"
+ " waitOperationSettings = settings.waitOperationSettings.toBuilder();\n"
+ " blockSettings = settings.blockSettings.toBuilder();\n"
+ " unaryMethodSettingsBuilders =\n"
+ " ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(\n"
+ " echoSettings, pagedExpandSettings, waitSettings, blockSettings);\n"
+ " }\n"
+ "\n"
+ " private static Builder initDefaults(Builder builder) {\n"
+ " builder\n"
+ " .echoSettings()\n"
Expand Down