diff --git a/src/main/java/com/google/api/generator/engine/ast/ClassDefinition.java b/src/main/java/com/google/api/generator/engine/ast/ClassDefinition.java index 40da0d793a..3098d5e32f 100644 --- a/src/main/java/com/google/api/generator/engine/ast/ClassDefinition.java +++ b/src/main/java/com/google/api/generator/engine/ast/ClassDefinition.java @@ -17,6 +17,7 @@ import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import javax.annotation.Nullable; @@ -85,8 +86,16 @@ public static Builder builder() { @AutoValue.Builder public abstract static class Builder { + public Builder setFileHeader(CommentStatement... headerComments) { + return setFileHeader(Arrays.asList(headerComments)); + } + public abstract Builder setFileHeader(List fileHeader); + public Builder setHeaderCommentStatements(CommentStatement... comments) { + return setHeaderCommentStatements(Arrays.asList(comments)); + } + public abstract Builder setHeaderCommentStatements( List headerCommentStatements); diff --git a/src/main/java/com/google/api/generator/engine/ast/JavaDocComment.java b/src/main/java/com/google/api/generator/engine/ast/JavaDocComment.java index 0bd2b67cd4..5e0a4665e8 100644 --- a/src/main/java/com/google/api/generator/engine/ast/JavaDocComment.java +++ b/src/main/java/com/google/api/generator/engine/ast/JavaDocComment.java @@ -28,6 +28,11 @@ public abstract class JavaDocComment implements Comment { @Override public abstract String comment(); + // Convenience helper for simple comments. + public static JavaDocComment withComment(String comment) { + return builder().addComment(comment).build(); + } + public static Builder builder() { return new AutoValue_JavaDocComment.Builder(); } diff --git a/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java b/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java index 285fc898dd..21feb7a1db 100644 --- a/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java +++ b/src/main/java/com/google/api/generator/engine/ast/MethodDefinition.java @@ -120,6 +120,10 @@ public abstract static class Builder { public abstract Builder setName(String name); + public Builder setHeaderCommentStatements(CommentStatement... comments) { + return setHeaderCommentStatements(Arrays.asList(comments)); + } + public abstract Builder setHeaderCommentStatements( List headeCommentStatements); diff --git a/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java b/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java index 60bb0420ef..cffdb4feec 100644 --- a/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java +++ b/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java @@ -725,6 +725,7 @@ public void visit(MethodDefinition methodDefinition) { rightBrace(); newline(); + newline(); } @Override @@ -796,7 +797,9 @@ public void visit(ClassDefinition classDefinition) { newline(); statements(classDefinition.statements()); + newline(); methods(classDefinition.methods()); + newline(); classes(classDefinition.nestedClasses()); rightBrace(); diff --git a/src/main/java/com/google/api/generator/gapic/utils/ApacheLicense.java b/src/main/java/com/google/api/generator/gapic/composer/CommentComposer.java similarity index 60% rename from src/main/java/com/google/api/generator/gapic/utils/ApacheLicense.java rename to src/main/java/com/google/api/generator/gapic/composer/CommentComposer.java index 00de28f7e5..8457288b82 100644 --- a/src/main/java/com/google/api/generator/gapic/utils/ApacheLicense.java +++ b/src/main/java/com/google/api/generator/gapic/composer/CommentComposer.java @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.api.generator.gapic.utils; +package com.google.api.generator.gapic.composer; import com.google.api.generator.engine.ast.BlockComment; import com.google.api.generator.engine.ast.CommentStatement; -import java.util.Arrays; -import java.util.List; +import com.google.api.generator.engine.ast.LineComment; -public class ApacheLicense { - private static final String fileHeaderString = +public class CommentComposer { + private static final String APACHE_LICENSE_STRING = "Copyright 2020 Google LLC\n\n" + "Licensed under the Apache License, Version 2.0 (the \"License\");\n" + "you may not use this file except in compliance with the License.\n" @@ -32,6 +31,19 @@ public class ApacheLicense { + "See the License for the specific language governing permissions and\n" + "limitations under the License."; - public static final List APACHE_LICENSE_COMMENT_STATEMENT = - Arrays.asList(CommentStatement.withComment(BlockComment.withComment(fileHeaderString))); + private static final String AUTO_GENERATED_CLASS_DISCLAIMER_STRING = + "AUTO-GENERATED DOCUMENTATION AND CLASS."; + + private static final String AUTO_GENERATED_METHOD_DISCLAIMER_STRING = + "AUTO-GENERATED DOCUMENTATION AND METHOD."; + + public static final CommentStatement APACHE_LICENSE_COMMENT = + CommentStatement.withComment(BlockComment.withComment(APACHE_LICENSE_STRING)); + + public static final CommentStatement AUTO_GENERATED_CLASS_COMMENT = + CommentStatement.withComment(LineComment.withComment(AUTO_GENERATED_CLASS_DISCLAIMER_STRING)); + + public static final CommentStatement AUTO_GENERATED_METHOD_COMMENT = + CommentStatement.withComment( + LineComment.withComment(AUTO_GENERATED_METHOD_DISCLAIMER_STRING)); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/Composer.java b/src/main/java/com/google/api/generator/gapic/composer/Composer.java index c193519023..ca50e1892d 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/Composer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/Composer.java @@ -23,7 +23,6 @@ import com.google.api.generator.gapic.model.Message; import com.google.api.generator.gapic.model.ResourceName; import com.google.api.generator.gapic.model.Service; -import com.google.api.generator.gapic.utils.ApacheLicense; import com.google.common.annotations.VisibleForTesting; import java.util.ArrayList; import java.util.List; @@ -117,7 +116,7 @@ protected static List addApacheLicense(List gapicClassLi gapicClass .classDefinition() .toBuilder() - .setFileHeader(ApacheLicense.APACHE_LICENSE_COMMENT_STATEMENT) + .setFileHeader(CommentComposer.APACHE_LICENSE_COMMENT) .build(); return GapicClass.create(gapicClass.kind(), classWithHeader); }) 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 4b8960b16f..e7b4b87072 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 @@ -103,6 +103,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Generated; @@ -123,6 +124,8 @@ public class ServiceStubSettingsClassComposer { "RETRYABLE_CODE_DEFINITIONS"; private static final String NESTED_RETRY_PARAM_DEFINITIONS_VAR_NAME = "RETRY_PARAM_DEFINITIONS"; private static final String STUB_PATTERN = "%sStub"; + + private static final String OPERATION_SETTINGS_LITERAL = "OperationSettings"; private static final String SETTINGS_LITERAL = "Settings"; private static final String LEFT_BRACE = "{"; @@ -160,6 +163,7 @@ public GapicClass generate( ClassDefinition classDef = ClassDefinition.builder() .setPackageString(pakkage) + .setHeaderCommentStatements(CommentComposer.AUTO_GENERATED_CLASS_COMMENT) .setAnnotations(createClassAnnotations()) .setScope(ScopeNode.PUBLIC) .setName(className) @@ -230,9 +234,11 @@ private static List createClassStatements( Map methodSettingsMemberVarExprs, Map messageTypes, Map types) { - List memberVarExprs = new ArrayList<>(); + Function exprToStatementFn = e -> ExprStatement.withExpr(e); + List statements = new ArrayList<>(); // Assign DEFAULT_SERVICE_SCOPES. + statements.add(ServiceStubSettingsCommentComposer.DEFAULT_SCOPES_COMMENT); VariableExpr defaultServiceScopesDeclVarExpr = DEFAULT_SERVICE_SCOPES_VAR_EXPR .toBuilder() @@ -263,38 +269,43 @@ private static List createClassStatements( .setReturnType(DEFAULT_SERVICE_SCOPES_VAR_EXPR.type()) .build(); - memberVarExprs.add( - AssignmentExpr.builder() - .setVariableExpr(defaultServiceScopesDeclVarExpr) - .setValueExpr(listBuilderExpr) - .build()); + statements.add( + exprToStatementFn.apply( + AssignmentExpr.builder() + .setVariableExpr(defaultServiceScopesDeclVarExpr) + .setValueExpr(listBuilderExpr) + .build())); // Declare settings members. - memberVarExprs.addAll( + statements.addAll( methodSettingsMemberVarExprs.values().stream() .map( v -> - v.toBuilder() - .setIsDecl(true) - .setScope(ScopeNode.PRIVATE) - .setIsFinal(true) - .build()) + exprToStatementFn.apply( + v.toBuilder() + .setIsDecl(true) + .setScope(ScopeNode.PRIVATE) + .setIsFinal(true) + .build())) .collect(Collectors.toList())); - memberVarExprs.addAll( - createPagingStaticAssignExprs(service, serviceConfig, messageTypes, types)); + statements.addAll( + createPagingStaticAssignExprs(service, serviceConfig, messageTypes, types).stream() + .map(e -> exprToStatementFn.apply(e)) + .collect(Collectors.toList())); for (Method method : service.methods()) { Optional batchingSettingOpt = serviceConfig.getBatchingSetting(service, method); if (batchingSettingOpt.isPresent()) { - memberVarExprs.add( - BatchingDescriptorComposer.createBatchingDescriptorFieldDeclExpr( - method, batchingSettingOpt.get(), messageTypes)); + statements.add( + exprToStatementFn.apply( + BatchingDescriptorComposer.createBatchingDescriptorFieldDeclExpr( + method, batchingSettingOpt.get(), messageTypes))); } } - return memberVarExprs.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList()); + return statements; } private static List createPagingStaticAssignExprs( @@ -703,7 +714,6 @@ private static List createClassMethods( javaMethods.addAll(createDefaultHelperAndGetterMethods(service, types)); javaMethods.addAll(createBuilderHelperMethods(service, types)); javaMethods.add(createClassConstructor(service, methodSettingsMemberVarExprs, types)); - // TODO(miraleung): Fill this out. return javaMethods; } @@ -712,6 +722,9 @@ private static List createMethodSettingsGetterMethods( Function, MethodDefinition> varToMethodFn = e -> MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.createCallSettingsGetterComment( + getMethodNameFromSettingsVarName(e.getKey()))) .setScope(ScopeNode.PUBLIC) .setReturnType(e.getValue().type()) .setName(e.getKey()) @@ -806,6 +819,8 @@ private static List createDefaultHelperAndGetterMethods( ConcreteReference.withClazz(InstantiatingExecutorProvider.Builder.class)); javaMethods.add( MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.DEFAULT_EXECUTOR_PROVIDER_BUILDER_METHOD_COMMENT) .setScope(ScopeNode.PUBLIC) .setIsStatic(true) .setReturnType(returnType) @@ -822,6 +837,8 @@ private static List createDefaultHelperAndGetterMethods( returnType = TypeNode.STRING; javaMethods.add( MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.DEFAULT_SERVICE_ENDPOINT_METHOD_COMMENT) .setScope(ScopeNode.PUBLIC) .setIsStatic(true) .setReturnType(returnType) @@ -838,6 +855,8 @@ private static List createDefaultHelperAndGetterMethods( .build()); javaMethods.add( MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.DEFAULT_SERVICE_SCOPES_METHOD_COMMENT) .setScope(ScopeNode.PUBLIC) .setIsStatic(true) .setReturnType(returnType) @@ -863,6 +882,9 @@ private static List createDefaultHelperAndGetterMethods( .build(); javaMethods.add( MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer + .DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT) .setScope(ScopeNode.PUBLIC) .setIsStatic(true) .setReturnType(returnType) @@ -893,6 +915,9 @@ private static List createDefaultHelperAndGetterMethods( .build(); javaMethods.add( MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer + .DEFAULT_GRPC_TRANSPORT_PROVIDER_BUILDER_METHOD_COMMENT) .setScope(ScopeNode.PUBLIC) .setIsStatic(true) .setReturnType(returnType) @@ -993,6 +1018,8 @@ private static List createBuilderHelperMethods( final TypeNode builderReturnType = types.get(NESTED_BUILDER_CLASS_NAME); javaMethods.add( MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.NEW_BUILDER_METHOD_COMMENT) .setScope(ScopeNode.PUBLIC) .setIsStatic(true) .setReturnType(builderReturnType) @@ -1016,6 +1043,8 @@ private static List createBuilderHelperMethods( .build()); javaMethods.add( MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.NEW_BUILDER_METHOD_COMMENT) .setScope(ScopeNode.PUBLIC) .setIsStatic(true) .setReturnType(builderReturnType) @@ -1027,6 +1056,8 @@ private static List createBuilderHelperMethods( // Create the toBuilder method. javaMethods.add( MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.TO_BUILDER_METHOD_COMMENT) .setScope(ScopeNode.PUBLIC) .setReturnType(builderReturnType) .setName("toBuilder") @@ -1116,6 +1147,9 @@ private static ClassDefinition createNestedBuilderClass( // TODO(miraleung): Fill this out. return ClassDefinition.builder() .setIsNested(true) + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.createBuilderClassComment( + getThisClassName(service.name()))) .setScope(ScopeNode.PUBLIC) .setIsStatic(true) .setName(className) @@ -1333,12 +1367,10 @@ private static List createNestedClassConstructorMethods( // Name is fooBarSettings. VariableExpr varExpr = e.getValue(); TypeNode varType = varExpr.type(); - String methodName = e.getKey(); Preconditions.checkState( - methodName.endsWith(SETTINGS_LITERAL), - String.format("%s expected to end with \"Settings\"", methodName)); - methodName = - methodName.substring(0, methodName.length() - SETTINGS_LITERAL.length()); + e.getKey().endsWith(SETTINGS_LITERAL), + String.format("%s expected to end with \"Settings\"", e.getKey())); + String methodName = getMethodNameFromSettingsVarName(e.getKey()); if (!isPagedCallSettingsBuilderFn.apply(varType)) { if (!isBatchingCallSettingsBuilderFn.apply(varType)) { @@ -1621,8 +1653,9 @@ private static MethodDefinition createNestedClassApplyToAllUnaryMethodsMethod( TypeNode returnType = types.get(NESTED_BUILDER_CLASS_NAME); Expr returnExpr = ValueExpr.withValue(ThisObjectValue.withType(returnType)); - // TODO(miraleung): Add major ver note. return MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.APPLY_TO_ALL_UNARY_METHODS_METHOD_COMMENTS) .setScope(ScopeNode.PUBLIC) .setReturnType(returnType) .setName(methodName) @@ -1669,6 +1702,9 @@ private static List createNestedClassSettingsBuilderGetterMeth isOperationCallSettingsBuilderFn.apply(settingsVarExpr.type()); javaMethods.add( MethodDefinition.builder() + .setHeaderCommentStatements( + ServiceStubSettingsCommentComposer.createCallSettingsBuilderGetterComment( + getMethodNameFromSettingsVarName(varName))) .setAnnotations(isOperationCallSettings ? lroBetaAnnotations : ImmutableList.of()) .setScope(ScopeNode.PUBLIC) .setReturnType(settingsVarExpr.type()) @@ -1964,4 +2000,17 @@ private static TypeNode getOperationCallSettingsType(Method method, boolean isSe .setGenerics(generics) .build()); } + + /** Turns a name like "waitSettings" or "waitOperationSettings" into "wait". */ + private static String getMethodNameFromSettingsVarName(String settingsVarName) { + BiFunction methodNameSubstrFn = + (s, literal) -> s.substring(0, s.length() - literal.length()); + if (settingsVarName.endsWith(OPERATION_SETTINGS_LITERAL)) { + return methodNameSubstrFn.apply(settingsVarName, OPERATION_SETTINGS_LITERAL); + } + if (settingsVarName.endsWith(SETTINGS_LITERAL)) { + return methodNameSubstrFn.apply(settingsVarName, SETTINGS_LITERAL); + } + return settingsVarName; + } } diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsCommentComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsCommentComposer.java new file mode 100644 index 0000000000..659c37d175 --- /dev/null +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsCommentComposer.java @@ -0,0 +1,82 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.api.generator.gapic.composer; + +import com.google.api.generator.engine.ast.CommentStatement; +import com.google.api.generator.engine.ast.JavaDocComment; +import com.google.api.generator.engine.ast.LineComment; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +class ServiceStubSettingsCommentComposer { + private static final String BUILDER_CLASS_DOC_PATTERN = "Builder for %s."; + private static final String CALL_SETTINGS_METHOD_DOC_PATTERN = + "Returns the object with the settings used for calls to %s."; + private static final String CALL_SETTINGS_BUILDER_METHOD_DOC_PATTERN = + "Returns the builder for the settings used for calls to %s."; + + static final CommentStatement DEFAULT_SCOPES_COMMENT = + toSimpleComment("The default scopes of the service."); + + static final CommentStatement DEFAULT_EXECUTOR_PROVIDER_BUILDER_METHOD_COMMENT = + toSimpleComment("Returns a builder for the default ExecutorProvider for this service."); + static final CommentStatement DEFAULT_SERVICE_ENDPOINT_METHOD_COMMENT = + toSimpleComment("Returns the default service endpoint."); + static final CommentStatement DEFAULT_SERVICE_SCOPES_METHOD_COMMENT = + toSimpleComment("Returns the default service scopes."); + + static final CommentStatement DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT = + toSimpleComment("Returns a builder for the default credentials for this service."); + + static final CommentStatement DEFAULT_GRPC_TRANSPORT_PROVIDER_BUILDER_METHOD_COMMENT = + toSimpleComment("Returns a builder for the default ChannelProvider for this service."); + + static final CommentStatement NEW_BUILDER_METHOD_COMMENT = + toSimpleComment("Returns a new builder for this class."); + + static final CommentStatement TO_BUILDER_METHOD_COMMENT = + toSimpleComment("Returns a builder containing all the values of this settings class."); + + static final List APPLY_TO_ALL_UNARY_METHODS_METHOD_COMMENTS = + Arrays.asList( + LineComment.withComment("NEXT_MAJOR_VER: remove 'throws Exception'."), + JavaDocComment.builder() + .addComment( + "Applies the given settings updater function to all of the unary API methods" + + " in this service.") + .addParagraph( + "Note: This method does not support applying settings to streaming methods.") + .build()) + .stream() + .map(c -> CommentStatement.withComment(c)) + .collect(Collectors.toList()); + + static CommentStatement createCallSettingsGetterComment(String javaMethodName) { + return toSimpleComment(String.format(CALL_SETTINGS_METHOD_DOC_PATTERN, javaMethodName)); + } + + static CommentStatement createBuilderClassComment(String outerClassName) { + return toSimpleComment(String.format(BUILDER_CLASS_DOC_PATTERN, outerClassName)); + } + + static CommentStatement createCallSettingsBuilderGetterComment(String javaMethodName) { + return toSimpleComment(String.format(CALL_SETTINGS_BUILDER_METHOD_DOC_PATTERN, javaMethodName)); + } + + private static CommentStatement toSimpleComment(String comment) { + return CommentStatement.withComment(JavaDocComment.withComment(comment)); + } +} diff --git a/src/test/java/com/google/api/generator/engine/JavaCodeGeneratorTest.java b/src/test/java/com/google/api/generator/engine/JavaCodeGeneratorTest.java index fef075d71a..1ee606f22b 100644 --- a/src/test/java/com/google/api/generator/engine/JavaCodeGeneratorTest.java +++ b/src/test/java/com/google/api/generator/engine/JavaCodeGeneratorTest.java @@ -835,8 +835,10 @@ private ClassDefinition createNestedClassNovel() { + " e.printStackTrace();\n" + " }\n" + " }\n" + + "\n" + " /**\n" - + " * Add books to Shelf and check if there is a novel, return string message as whether novel books\n" + + " * Add books to Shelf and check if there is a novel, return string message as" + + " whether novel books\n" + " * are added to the shelf.\n" + " *\n" + " * @param shelf The Shelf object to which books will put.\n" @@ -852,6 +854,7 @@ private ClassDefinition createNestedClassNovel() { + " }\n" + " return containsNovel ? \"Added novels\" : \"No novels added\";\n" + " }\n" + + "\n" + " // Private helper.\n" + " private Book addBookToShelf(BookKind bookKind, Shelf shelf) {\n" + " Book book =\n" @@ -884,6 +887,7 @@ private ClassDefinition createNestedClassNovel() { + " }\n" + "\n" + " public class Novel extends Book {\n" + + "\n" + " @Override\n" + " public void createBook(int seriesNum, BookKind bookKind) {\n" + " this.seriesNum = seriesNum;\n" diff --git a/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java b/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java index 1ebe8c0d9f..25b3179c56 100644 --- a/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java +++ b/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java @@ -883,7 +883,7 @@ public void writeAnonymousClassExpr_basic() { "new Runnable() {\n", "@Override\n", "public void run() {\n", - "boolean foobar = false;\n}\n}")); + "boolean foobar = false;\n}\n\n}")); } @Test @@ -928,7 +928,7 @@ public void writeAnonymousClassExpr_withStatementsMethods() { "private static final String s = \"foo\";\n", "@Override\n", "public void run() {\n", - "int x = 3;\n}\n}"); + "int x = 3;\n}\n\n}"); assertEquals(writerVisitor.write(), expected); } @@ -985,7 +985,7 @@ public void writeAnonymousClassExpr_generics() { "@Override\n", "public MethodDefinition apply(List arg) {\n", "return returnArg;\n", - "}\n}"); + "}\n\n}"); assertEquals(writerVisitor.write(), expected); } @@ -1499,7 +1499,7 @@ public void writeMethodDefinition_basic() { methodDefinition.accept(writerVisitor); assertEquals( writerVisitor.write(), - String.format("%s%s%s", "public void close() {\n", "int x = 3;\n", "}\n")); + String.format("%s%s%s", "public void close() {\n", "int x = 3;\n", "}\n\n")); } @Test @@ -1517,7 +1517,7 @@ public void writeMethodDefinition_constructor() { .build(); methodDefinition.accept(writerVisitor); - assertEquals(writerVisitor.write(), "public LibrarySettings() {\n}\n"); + assertEquals(writerVisitor.write(), "public LibrarySettings() {\n}\n\n"); } @Test @@ -1530,7 +1530,7 @@ public void writeMethodDefinition_basicEmptyBody() { .build(); methodDefinition.accept(writerVisitor); - assertEquals(writerVisitor.write(), "public void close() {\n}\n"); + assertEquals(writerVisitor.write(), "public void close() {\n}\n\n"); } @Test @@ -1548,7 +1548,7 @@ public void writeMethodDefinition_basicAbstract() { methodDefinition.accept(writerVisitor); assertEquals( writerVisitor.write(), - String.format("%s%s%s", "public abstract void close() {\n", "int x = 3;\n", "}\n")); + String.format("%s%s%s", "public abstract void close() {\n", "int x = 3;\n", "}\n\n")); } @Test @@ -1602,7 +1602,7 @@ public void writeMethodDefinition_withArgumentsAndReturnExpr() { "public int close(int x, int y) {\n", "boolean foobar = false;\n", "return 3;\n", - "}\n")); + "}\n\n")); } @Test @@ -1679,7 +1679,7 @@ public void writeMethodDefinition_withCommentsAnnotationsAndThrows() { "}\n", "boolean foobar = false;\n", "return 3;\n", - "}\n"); + "}\n\n"); assertEquals(writerVisitor.write(), expected); } @@ -1722,7 +1722,7 @@ public void writeMethodDefinition_templatedReturnTypeAndArguments() { createLines(3), "public Map close(Map x, Map y) {\n", "return foobar();\n", - "}\n")); + "}\n\n")); } @Test @@ -1913,7 +1913,7 @@ public void writeClassDefinition_commentsStatementsAndMethods() { " boolean foobar = false;\n", " }\n", "\n", - " private static class IAmANestedClass {\n", + " private static class IAmANestedClass {\n\n", " public boolean open() {\n", " return true;\n", " }\n", @@ -1971,7 +1971,7 @@ public void writeThisObjectValue_methodReturn() { methodDefinition.accept(writerVisitor); assertEquals( writerVisitor.write(), - String.format("public Student apply() {\n" + "return this;\n" + "}\n")); + String.format("public Student apply() {\n" + "return this;\n" + "}\n\n")); } @Test diff --git a/src/test/java/com/google/api/generator/gapic/composer/BatchingDescriptorComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/BatchingDescriptorComposerTest.java index 844f8b3cbd..0780e85fe8 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/BatchingDescriptorComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/BatchingDescriptorComposerTest.java @@ -110,6 +110,7 @@ public void batchingDescriptor_hasSubresponseField() { "public PartitionKey getBatchPartitionKey(PublishRequest request) {\n", "return new PartitionKey(request.getTopic());\n", "}\n", + "\n", "@Override\n", "public RequestBuilder getRequestBuilder() {\n", "return new RequestBuilder() {\n", @@ -122,16 +123,18 @@ public void batchingDescriptor_hasSubresponseField() { "builder.addAllMessages(request.getMessagesList());\n", "}\n", "}\n", + "\n", "@Override\n", "public PublishRequest build() {\n", "return builder.build();\n", "}\n", + "\n", "};\n", "}\n", + "\n", "@Override\n", - "public void splitResponse(", - "PublishResponse batchResponse, ", - "Collection> batch) {\n", + "public void splitResponse(PublishResponse batchResponse, Collection> batch) {\n", "int batchMessageIndex = 0;\n", "for (BatchedRequestIssuer responder : batch) {\n", "List subresponseElements = new ArrayList<>();\n", @@ -139,28 +142,32 @@ public void batchingDescriptor_hasSubresponseField() { "for (int i = 0; i < subresponseCount; i++) {\n", "subresponseElements.add(batchResponse.getMessageIds(batchMessageIndex));\n", "}\n", - "PublishResponse response = ", - "PublishResponse.newBuilder().addAllMessageIds(subresponseElements).build();\n", + "PublishResponse response =" + + " PublishResponse.newBuilder().addAllMessageIds(subresponseElements).build();\n", "responder.setResponse(response);\n", "}\n", "}\n", + "\n", "@Override\n", - "public void splitException(", - "Throwable throwable, ", - "Collection> batch) {\n", + "public void splitException(Throwable throwable, Collection> batch) {\n", "for (BatchedRequestIssuer responder : batch) {\n", "responder.setException(throwable);\n", "}\n", "}\n", + "\n", "@Override\n", "public long countElements(PublishRequest request) {\n", "return request.getMessagesCount();\n", "}\n", + "\n", "@Override\n", "public long countBytes(PublishRequest request) {\n", "return request.getSerializedSize();\n", "}\n", + "\n", "}"); + assertEquals(expected, writerVisitor.write()); } @@ -223,6 +230,7 @@ public void batchingDescriptor_noSubresponseField() { "return new PartitionKey(request.getLogName(), request.getResource()," + " request.getLabels());\n", "}\n", + "\n", "@Override\n", "public RequestBuilder getRequestBuilder() {\n", "return new RequestBuilder() {\n", @@ -235,36 +243,42 @@ public void batchingDescriptor_noSubresponseField() { "builder.addAllEntries(request.getEntriesList());\n", "}\n", "}\n", + "\n", "@Override\n", "public WriteLogEntriesRequest build() {\n", "return builder.build();\n", "}\n", + "\n", "};\n", "}\n", + "\n", "@Override\n", - "public void splitResponse(WriteLogEntriesResponse batchResponse, ", - "Collection> batch) {\n", + "public void splitResponse(WriteLogEntriesResponse batchResponse, Collection> batch) {\n", "for (BatchedRequestIssuer responder : batch) {\n", "WriteLogEntriesResponse response = WriteLogEntriesResponse.newBuilder().build();\n", "responder.setResponse(response);\n", "}\n", "}\n", + "\n", "@Override\n", - "public void splitException(", - "Throwable throwable, ", - "Collection> batch) {\n", + "public void splitException(Throwable throwable, Collection> batch) {\n", "for (BatchedRequestIssuer responder : batch) {\n", "responder.setException(throwable);\n", "}\n", "}\n", + "\n", "@Override\n", "public long countElements(WriteLogEntriesRequest request) {\n", "return request.getEntriesCount();\n", "}\n", + "\n", "@Override\n", "public long countBytes(WriteLogEntriesRequest request) {\n", "return request.getSerializedSize();\n", "}\n", + "\n", "}"); assertEquals(expected, writerVisitor.write()); diff --git a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java index 2498618e01..c935ceca41 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java @@ -85,6 +85,7 @@ public void generateServiceClasses() { + "\n" + "@Generated(\"by gapic-generator\")\n" + "public class GrpcEchoCallableFactory implements GrpcStubCallableFactory {\n" + + "\n" + " @Override\n" + " public UnaryCallable" + " createUnaryCallable(\n" diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java index 91034d9792..6490109316 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java @@ -89,6 +89,7 @@ public void generateServiceClasses() { + "\n" + "@Generated(\"by gapic-generator-java\")\n" + "public class EchoSettings extends ClientSettings {\n" + + "\n" + " public UnaryCallSettings echoSettings() {\n" + " return ((EchoStubSettings) getStubSettings()).echoSettings();\n" + " }\n" @@ -186,6 +187,7 @@ public void generateServiceClasses() { + "\n" + " public static class Builder extends ClientSettings.Builder" + " {\n" + + "\n" + " protected Builder() throws IOException {\n" + " this(((ClientContext) null));\n" + " }\n" diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java index f494c7afb4..54d9ef5051 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java @@ -84,6 +84,7 @@ public void generateServiceClasses() { + "\n" + "@Generated(\"by gapic-generator\")\n" + "public abstract class EchoStub implements BackgroundResource {\n" + + "\n" + " public OperationsStub getOperationsStub() {\n" + " throw new UnsupportedOperationException(\"Not implemented:" + " getOperationsStub()\");\n" 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 52b025ead1..1415ba3fd7 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 @@ -228,12 +228,15 @@ private static List parseServices( + "import javax.annotation.Generated;\n" + "import org.threeten.bp.Duration;\n" + "\n" + + "// AUTO-GENERATED DOCUMENTATION AND CLASS.\n" + "@BetaApi\n" + "@Generated(\"by gapic-generator-java\")\n" + "public class EchoStubSettings extends StubSettings {\n" + + " /** The default scopes of the service. */\n" + " private static final ImmutableList DEFAULT_SERVICE_SCOPES =\n" + " " + " ImmutableList.builder().add(\"https://www.googleapis.com/auth/cloud-platform\").build();\n" + + "\n" + " private final UnaryCallSettings echoSettings;\n" + " private final ServerStreamingCallSettings" + " expandSettings;\n" @@ -310,42 +313,51 @@ private static List parseServices( + " }\n" + " };\n" + "\n" + + " /** Returns the object with the settings used for calls to echo. */\n" + " public UnaryCallSettings echoSettings() {\n" + " return echoSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to expand. */\n" + " public ServerStreamingCallSettings expandSettings()" + " {\n" + " return expandSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to collect. */\n" + " public StreamingCallSettings collectSettings() {\n" + " return collectSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to chat. */\n" + " public StreamingCallSettings chatSettings() {\n" + " return chatSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to chatAgain. */\n" + " public StreamingCallSettings chatAgainSettings() {\n" + " return chatAgainSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to pagedExpand. */\n" + " public PagedCallSettings\n" + " pagedExpandSettings() {\n" + " return pagedExpandSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to wait. */\n" + " public UnaryCallSettings waitSettings() {\n" + " return waitSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to wait. */\n" + " public OperationCallSettings" + " waitOperationSettings() {\n" + " return waitOperationSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to block. */\n" + " public UnaryCallSettings blockSettings() {\n" + " return blockSettings;\n" + " }\n" @@ -364,25 +376,30 @@ private static List parseServices( + " getTransportChannelProvider().getTransportName()));\n" + " }\n" + "\n" + + " /** Returns a builder for the default ExecutorProvider for this service. */\n" + " public static InstantiatingExecutorProvider.Builder" + " defaultExecutorProviderBuilder() {\n" + " return InstantiatingExecutorProvider.newBuilder();\n" + " }\n" + "\n" + + " /** Returns the default service endpoint. */\n" + " public static String getDefaultEndpoint() {\n" + " return \"localhost:7469\";\n" + " }\n" + "\n" + + " /** Returns the default service scopes. */\n" + " public static List getDefaultServiceScopes() {\n" + " return DEFAULT_SERVICE_SCOPES;\n" + " }\n" + "\n" + + " /** Returns a builder for the default credentials for this service. */\n" + " public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder()" + " {\n" + " return" + " GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES);\n" + " }\n" + "\n" + + " /** Returns a builder for the default ChannelProvider for this service. */\n" + " public static InstantiatingGrpcChannelProvider.Builder" + " defaultGrpcTransportProviderBuilder() {\n" + " return InstantiatingGrpcChannelProvider.newBuilder()\n" @@ -405,14 +422,17 @@ private static List parseServices( + " GaxGrpcProperties.getGrpcVersion());\n" + " }\n" + "\n" + + " /** Returns a new builder for this class. */\n" + " public static Builder newBuilder() {\n" + " return Builder.createDefault();\n" + " }\n" + "\n" + + " /** Returns a new builder for this class. */\n" + " public static Builder newBuilder(ClientContext clientContext) {\n" + " return new Builder(clientContext);\n" + " }\n" + "\n" + + " /** Returns a builder containing all the values of this settings class. */\n" + " public Builder toBuilder() {\n" + " return new Builder(this);\n" + " }\n" @@ -430,6 +450,7 @@ private static List parseServices( + " blockSettings = settingsBuilder.blockSettings().build();\n" + " }\n" + "\n" + + " /** Builder for EchoStubSettings. */\n" + " public static class Builder extends StubSettings.Builder {\n" + " private final ImmutableList>" + " unaryMethodSettingsBuilders;\n" @@ -603,6 +624,14 @@ private static List parseServices( + " return builder;\n" + " }\n" + "\n" + + " // NEXT_MAJOR_VER: remove 'throws Exception'.\n" + + " /**\n" + + " * Applies the given settings updater function to all of the unary API methods in" + + " this service.\n" + + " *\n" + + " *

Note: This method does not support applying settings to streaming" + + " methods.\n" + + " */\n" + " public Builder applyToAllUnaryMethods(\n" + " ApiFunction, Void> settingsUpdater) throws" + " Exception {\n" @@ -615,40 +644,48 @@ private static List parseServices( + " return unaryMethodSettingsBuilders;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to echo. */\n" + " public UnaryCallSettings.Builder echoSettings() {\n" + " return echoSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to expand. */\n" + " public ServerStreamingCallSettings.Builder" + " expandSettings() {\n" + " return expandSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to collect. */\n" + " public StreamingCallSettings.Builder collectSettings()" + " {\n" + " return collectSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to chat. */\n" + " public StreamingCallSettings.Builder chatSettings()" + " {\n" + " return chatSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to chatAgain. */\n" + " public StreamingCallSettings.Builder" + " chatAgainSettings() {\n" + " return chatAgainSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to pagedExpand. */\n" + " public PagedCallSettings.Builder<\n" + " PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse>\n" + " pagedExpandSettings() {\n" + " return pagedExpandSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to wait. */\n" + " public UnaryCallSettings.Builder waitSettings() {\n" + " return waitSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to wait. */\n" + " @BetaApi(\n" + " \"The surface for use by generated code is not stable yet and may change in" + " the future.\")\n" @@ -657,6 +694,7 @@ private static List parseServices( + " return waitOperationSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to block. */\n" + " public UnaryCallSettings.Builder blockSettings() {\n" + " return blockSettings;\n" + " }\n" @@ -730,10 +768,12 @@ private static List parseServices( + "import javax.annotation.Generated;\n" + "import org.threeten.bp.Duration;\n" + "\n" + + "// AUTO-GENERATED DOCUMENTATION AND CLASS.\n" + "@BetaApi\n" + "@Generated(\"by gapic-generator-java\")\n" + "public class LoggingServiceV2StubSettings extends" + " StubSettings {\n" + + " /** The default scopes of the service. */\n" + " private static final ImmutableList DEFAULT_SERVICE_SCOPES =\n" + " ImmutableList.builder()\n" + " .add(\"https://www.googleapis.com/auth/cloud-platform\")\n" @@ -742,6 +782,7 @@ private static List parseServices( + " .add(\"https://www.googleapis.com/auth/logging.read\")\n" + " .add(\"https://www.googleapis.com/auth/logging.write\")\n" + " .build();\n" + + "\n" + " private final UnaryCallSettings deleteLogSettings;\n" + " private final BatchingCallSettings\n" @@ -1033,15 +1074,18 @@ private static List parseServices( + " }\n" + " };\n" + "\n" + + " /** Returns the object with the settings used for calls to deleteLog. */\n" + " public UnaryCallSettings deleteLogSettings() {\n" + " return deleteLogSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to writeLogEntries. */\n" + " public BatchingCallSettings\n" + " writeLogEntriesSettings() {\n" + " return writeLogEntriesSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to listLogEntries. */\n" + " public PagedCallSettings<\n" + " ListLogEntriesRequest, ListLogEntriesResponse," + " ListLogEntriesPagedResponse>\n" @@ -1049,6 +1093,8 @@ private static List parseServices( + " return listLogEntriesSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to" + + " listMonitoredResourceDescriptors. */\n" + " public PagedCallSettings<\n" + " ListMonitoredResourceDescriptorsRequest,\n" + " ListMonitoredResourceDescriptorsResponse,\n" @@ -1057,6 +1103,7 @@ private static List parseServices( + " return listMonitoredResourceDescriptorsSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to listLogs. */\n" + " public PagedCallSettings\n" + " listLogsSettings() {\n" @@ -1077,25 +1124,30 @@ private static List parseServices( + " getTransportChannelProvider().getTransportName()));\n" + " }\n" + "\n" + + " /** Returns a builder for the default ExecutorProvider for this service. */\n" + " public static InstantiatingExecutorProvider.Builder" + " defaultExecutorProviderBuilder() {\n" + " return InstantiatingExecutorProvider.newBuilder();\n" + " }\n" + "\n" + + " /** Returns the default service endpoint. */\n" + " public static String getDefaultEndpoint() {\n" + " return \"logging.googleapis.com:443\";\n" + " }\n" + "\n" + + " /** Returns the default service scopes. */\n" + " public static List getDefaultServiceScopes() {\n" + " return DEFAULT_SERVICE_SCOPES;\n" + " }\n" + "\n" + + " /** Returns a builder for the default credentials for this service. */\n" + " public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder()" + " {\n" + " return" + " GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES);\n" + " }\n" + "\n" + + " /** Returns a builder for the default ChannelProvider for this service. */\n" + " public static InstantiatingGrpcChannelProvider.Builder" + " defaultGrpcTransportProviderBuilder() {\n" + " return InstantiatingGrpcChannelProvider.newBuilder()\n" @@ -1119,14 +1171,17 @@ private static List parseServices( + " GaxGrpcProperties.getGrpcVersion());\n" + " }\n" + "\n" + + " /** Returns a new builder for this class. */\n" + " public static Builder newBuilder() {\n" + " return Builder.createDefault();\n" + " }\n" + "\n" + + " /** Returns a new builder for this class. */\n" + " public static Builder newBuilder(ClientContext clientContext) {\n" + " return new Builder(clientContext);\n" + " }\n" + "\n" + + " /** Returns a builder containing all the values of this settings class. */\n" + " public Builder toBuilder() {\n" + " return new Builder(this);\n" + " }\n" @@ -1142,6 +1197,7 @@ private static List parseServices( + " listLogsSettings = settingsBuilder.listLogsSettings().build();\n" + " }\n" + "\n" + + " /** Builder for LoggingServiceV2StubSettings. */\n" + " public static class Builder extends StubSettings.Builder {\n" + " private final ImmutableList>" @@ -1302,6 +1358,14 @@ private static List parseServices( + " return builder;\n" + " }\n" + "\n" + + " // NEXT_MAJOR_VER: remove 'throws Exception'.\n" + + " /**\n" + + " * Applies the given settings updater function to all of the unary API methods in" + + " this service.\n" + + " *\n" + + " *

Note: This method does not support applying settings to streaming" + + " methods.\n" + + " */\n" + " public Builder applyToAllUnaryMethods(\n" + " ApiFunction, Void> settingsUpdater) throws" + " Exception {\n" @@ -1314,16 +1378,19 @@ private static List parseServices( + " return unaryMethodSettingsBuilders;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to deleteLog. */\n" + " public UnaryCallSettings.Builder deleteLogSettings() {\n" + " return deleteLogSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to writeLogEntries. */\n" + " public BatchingCallSettings.Builder\n" + " writeLogEntriesSettings() {\n" + " return writeLogEntriesSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to listLogEntries. */\n" + " public PagedCallSettings.Builder<\n" + " ListLogEntriesRequest, ListLogEntriesResponse," + " ListLogEntriesPagedResponse>\n" @@ -1331,6 +1398,8 @@ private static List parseServices( + " return listLogEntriesSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to" + + " listMonitoredResourceDescriptors. */\n" + " public PagedCallSettings.Builder<\n" + " ListMonitoredResourceDescriptorsRequest,\n" + " ListMonitoredResourceDescriptorsResponse,\n" @@ -1339,6 +1408,7 @@ private static List parseServices( + " return listMonitoredResourceDescriptorsSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to listLogs. */\n" + " public PagedCallSettings.Builder\n" + " listLogsSettings() {\n" @@ -1417,14 +1487,17 @@ private static List parseServices( + "import javax.annotation.Generated;\n" + "import org.threeten.bp.Duration;\n" + "\n" + + "// AUTO-GENERATED DOCUMENTATION AND CLASS.\n" + "@BetaApi\n" + "@Generated(\"by gapic-generator-java\")\n" + "public class PublisherStubSettings extends StubSettings {\n" + + " /** The default scopes of the service. */\n" + " private static final ImmutableList DEFAULT_SERVICE_SCOPES =\n" + " ImmutableList.builder()\n" + " .add(\"https://www.googleapis.com/auth/cloud-platform\")\n" + " .add(\"https://www.googleapis.com/auth/pubsub\")\n" + " .build();\n" + + "\n" + " private final UnaryCallSettings createTopicSettings;\n" + " private final UnaryCallSettings updateTopicSettings;\n" + " private final BatchingCallSettings" @@ -1714,28 +1787,35 @@ private static List parseServices( + " }\n" + " };\n" + "\n" + + " /** Returns the object with the settings used for calls to createTopic. */\n" + " public UnaryCallSettings createTopicSettings() {\n" + " return createTopicSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to updateTopic. */\n" + " public UnaryCallSettings updateTopicSettings() {\n" + " return updateTopicSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to publish. */\n" + " public BatchingCallSettings publishSettings() {\n" + " return publishSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to getTopic. */\n" + " public UnaryCallSettings getTopicSettings() {\n" + " return getTopicSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to listTopics. */\n" + " public PagedCallSettings\n" + " listTopicsSettings() {\n" + " return listTopicsSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to listTopicSubscriptions." + + " */\n" + " public PagedCallSettings<\n" + " ListTopicSubscriptionsRequest,\n" + " ListTopicSubscriptionsResponse,\n" @@ -1744,6 +1824,7 @@ private static List parseServices( + " return listTopicSubscriptionsSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to listTopicSnapshots. */\n" + " public PagedCallSettings<\n" + " ListTopicSnapshotsRequest, ListTopicSnapshotsResponse," + " ListTopicSnapshotsPagedResponse>\n" @@ -1751,10 +1832,12 @@ private static List parseServices( + " return listTopicSnapshotsSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to deleteTopic. */\n" + " public UnaryCallSettings deleteTopicSettings() {\n" + " return deleteTopicSettings;\n" + " }\n" + "\n" + + " /** Returns the object with the settings used for calls to detachSubscription. */\n" + " public UnaryCallSettings\n" + " detachSubscriptionSettings() {\n" + " return detachSubscriptionSettings;\n" @@ -1774,25 +1857,30 @@ private static List parseServices( + " getTransportChannelProvider().getTransportName()));\n" + " }\n" + "\n" + + " /** Returns a builder for the default ExecutorProvider for this service. */\n" + " public static InstantiatingExecutorProvider.Builder" + " defaultExecutorProviderBuilder() {\n" + " return InstantiatingExecutorProvider.newBuilder();\n" + " }\n" + "\n" + + " /** Returns the default service endpoint. */\n" + " public static String getDefaultEndpoint() {\n" + " return \"pubsub.googleapis.com:443\";\n" + " }\n" + "\n" + + " /** Returns the default service scopes. */\n" + " public static List getDefaultServiceScopes() {\n" + " return DEFAULT_SERVICE_SCOPES;\n" + " }\n" + "\n" + + " /** Returns a builder for the default credentials for this service. */\n" + " public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder()" + " {\n" + " return" + " GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES);\n" + " }\n" + "\n" + + " /** Returns a builder for the default ChannelProvider for this service. */\n" + " public static InstantiatingGrpcChannelProvider.Builder" + " defaultGrpcTransportProviderBuilder() {\n" + " return InstantiatingGrpcChannelProvider.newBuilder()\n" @@ -1815,14 +1903,17 @@ private static List parseServices( + " GaxGrpcProperties.getGrpcVersion());\n" + " }\n" + "\n" + + " /** Returns a new builder for this class. */\n" + " public static Builder newBuilder() {\n" + " return Builder.createDefault();\n" + " }\n" + "\n" + + " /** Returns a new builder for this class. */\n" + " public static Builder newBuilder(ClientContext clientContext) {\n" + " return new Builder(clientContext);\n" + " }\n" + "\n" + + " /** Returns a builder containing all the values of this settings class. */\n" + " public Builder toBuilder() {\n" + " return new Builder(this);\n" + " }\n" @@ -1843,6 +1934,7 @@ private static List parseServices( + " settingsBuilder.detachSubscriptionSettings().build();\n" + " }\n" + "\n" + + " /** Builder for PublisherStubSettings. */\n" + " public static class Builder extends StubSettings.Builder" + " {\n" + " private final ImmutableList>" @@ -2083,6 +2175,14 @@ private static List parseServices( + " return builder;\n" + " }\n" + "\n" + + " // NEXT_MAJOR_VER: remove 'throws Exception'.\n" + + " /**\n" + + " * Applies the given settings updater function to all of the unary API methods in" + + " this service.\n" + + " *\n" + + " *

Note: This method does not support applying settings to streaming" + + " methods.\n" + + " */\n" + " public Builder applyToAllUnaryMethods(\n" + " ApiFunction, Void> settingsUpdater) throws" + " Exception {\n" @@ -2095,30 +2195,37 @@ private static List parseServices( + " return unaryMethodSettingsBuilders;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to createTopic. */\n" + " public UnaryCallSettings.Builder createTopicSettings() {\n" + " return createTopicSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to updateTopic. */\n" + " public UnaryCallSettings.Builder updateTopicSettings()" + " {\n" + " return updateTopicSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to publish. */\n" + " public BatchingCallSettings.Builder" + " publishSettings() {\n" + " return publishSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to getTopic. */\n" + " public UnaryCallSettings.Builder getTopicSettings() {\n" + " return getTopicSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to listTopics. */\n" + " public PagedCallSettings.Builder\n" + " listTopicsSettings() {\n" + " return listTopicsSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to" + + " listTopicSubscriptions. */\n" + " public PagedCallSettings.Builder<\n" + " ListTopicSubscriptionsRequest,\n" + " ListTopicSubscriptionsResponse,\n" @@ -2127,6 +2234,8 @@ private static List parseServices( + " return listTopicSubscriptionsSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to listTopicSnapshots." + + " */\n" + " public PagedCallSettings.Builder<\n" + " ListTopicSnapshotsRequest, ListTopicSnapshotsResponse," + " ListTopicSnapshotsPagedResponse>\n" @@ -2134,11 +2243,14 @@ private static List parseServices( + " return listTopicSnapshotsSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to deleteTopic. */\n" + " public UnaryCallSettings.Builder deleteTopicSettings()" + " {\n" + " return deleteTopicSettings;\n" + " }\n" + "\n" + + " /** Returns the builder for the settings used for calls to detachSubscription." + + " */\n" + " public UnaryCallSettings.Builder\n" + " detachSubscriptionSettings() {\n"