diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java index 9076b4c219..3aaa35301d 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java @@ -1170,8 +1170,8 @@ private static List 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; } @@ -1556,6 +1556,43 @@ private static MethodDefinition createNestedClassUnaryMethodSettingsBuilderGette .build(); } + private static List createNestedClassSettingsBuilderGetterMethods( + Map nestedMethodSettingsMemberVarExprs) { + Reference operationCallSettingsBuilderRef = + ConcreteReference.withClazz(OperationCallSettings.Builder.class); + Function isOperationCallSettingsBuilderFn = + t -> + t.reference() + .copyAndSetGenerics(ImmutableList.of()) + .equals(operationCallSettingsBuilderRef); + List 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 javaMethods = new ArrayList<>(); + for (Map.Entry 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 types) { TypeNode outerClassType = types.get(getThisClassName(service.name())); diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java index 50f978ef1f..75cb1b3275 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java @@ -518,6 +518,52 @@ public void generateServiceClasses() { + " return unaryMethodSettingsBuilders;\n" + " }\n" + "\n" + + " public UnaryCallSettings.Builder echoSettings() {\n" + + " return echoSettings;\n" + + " }\n" + + "\n" + + " public ServerStreamingCallSettings.Builder" + + " expandSettings() {\n" + + " return expandSettings;\n" + + " }\n" + + "\n" + + " public StreamingCallSettings.Builder collectSettings()" + + " {\n" + + " return collectSettings;\n" + + " }\n" + + "\n" + + " public StreamingCallSettings.Builder chatSettings()" + + " {\n" + + " return chatSettings;\n" + + " }\n" + + "\n" + + " public StreamingCallSettings.Builder" + + " 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 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\n" + + " waitOperationSettings() {\n" + + " return waitOperationSettings;\n" + + " }\n" + + "\n" + + " public UnaryCallSettings.Builder blockSettings() {\n" + + " return blockSettings;\n" + + " }\n" + + "\n" + " @Override\n" + " public EchoStubSettings build() throws IOException {\n" + " return new EchoStubSettings(this);\n"