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][engx] refactor: move comment composers into dedicated package #618

Merged
merged 27 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8bc63f4
fix: fix dep ordering in Bazel dedupe rules
miraleung Dec 2, 2020
43307c0
Merge branch 'master' of github.com:googleapis/gapic-generator-java
miraleung Dec 2, 2020
6a139fa
Merge branch 'master' of github.com:googleapis/gapic-generator-java
miraleung Dec 3, 2020
5db4adb
Merge branch 'master' of github.com:googleapis/gapic-generator-java
miraleung Dec 4, 2020
82d628d
Merge branch 'master' of github.com:googleapis/gapic-generator-java
miraleung Dec 7, 2020
1669fd6
Merge branch 'master' of github.com:googleapis/gapic-generator-java
miraleung Dec 9, 2020
06c7f46
Merge branch 'master' of github.com:googleapis/gapic-generator-java
miraleung Dec 10, 2020
ecfe117
Merge branch 'master' of github.com:googleapis/gapic-generator-java
miraleung Dec 15, 2020
3f4b145
Merge branch 'master' of github.com:googleapis/gapitc-generator-java
miraleung Dec 17, 2020
0d92bec
Merge remote-tracking branch 'origin/master'
miraleung Dec 21, 2020
c2e56c1
fix: filter out unbound vars in HttpRuleParser
miraleung Dec 21, 2020
a14a1b1
fix: use nested types in message store key, filter out subtypes in ty…
miraleung Dec 21, 2020
af420ac
refactor: make TypeNode map a TypeStore class
miraleung Dec 21, 2020
7a3f6c2
fix: remove superfluous varexpr helper in ServiceClientClassComposer
miraleung Dec 21, 2020
980e5bd
fix: move varexpr helper to local lambda for better locality
miraleung Dec 22, 2020
18737e1
fix: move ServiceClientSampleCodeComposer to composer.samplecode
miraleung Dec 22, 2020
f94bca8
refactor: pull sample code creation out of ServiceClientCommentComposer
miraleung Dec 22, 2020
7c58e0b
refactor: move comment composers into dedicated package
miraleung Dec 22, 2020
5e8a564
fix: remove BiFunction
miraleung Dec 22, 2020
b45d41b
Merge remote-tracking branch 'origin/dev/a4' into dev/a5
miraleung Dec 22, 2020
8f991b2
Merge remote-tracking branch 'origin/dev/a5' into dev/a6
miraleung Dec 22, 2020
84421ff
fix: merge master
miraleung Dec 22, 2020
40434ae
Merge remote-tracking branch 'origin/dev/a5' into dev/a6
miraleung Dec 22, 2020
404b5c0
Merge branch 'master' into dev/a6
miraleung Dec 22, 2020
aa245c8
fix: merge master
miraleung Dec 22, 2020
1a7ca92
Merge branch 'dev/a6' into dev/a7
miraleung Dec 22, 2020
f589886
fix: merge master
miraleung Dec 22, 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
1 change: 1 addition & 0 deletions src/main/java/com/google/api/generator/gapic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ filegroup(
name = "gapic_files",
srcs = glob(["*.java"]) + [
"//src/main/java/com/google/api/generator/gapic/composer:composer_files",
"//src/main/java/com/google/api/generator/gapic/composer/comment:comment_files",
"//src/main/java/com/google/api/generator/gapic/composer/samplecode:samplecode_files",
"//src/main/java/com/google/api/generator/gapic/composer/store:store_files",
"//src/main/java/com/google/api/generator/gapic/model:model_files",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ java_library(
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/engine/writer",
"//src/main/java/com/google/api/generator/gapic:status_java_proto",
"//src/main/java/com/google/api/generator/gapic/composer/comment",
"//src/main/java/com/google/api/generator/gapic/composer/samplecode",
"//src/main/java/com/google/api/generator/gapic/composer/store",
"//src/main/java/com/google/api/generator/gapic/composer/utils",
"//src/main/java/com/google/api/generator/gapic/model",
"//src/main/java/com/google/api/generator/gapic/utils",
"@com_google_api_api_common//jar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.api.generator.engine.ast.JavaDocComment;
import com.google.api.generator.engine.ast.PackageInfoDefinition;
import com.google.api.generator.engine.ast.TypeNode;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.GapicContext;
import com.google.api.generator.gapic.model.GapicPackageInfo;
import com.google.api.generator.gapic.model.Service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.api.generator.engine.ast.ClassDefinition;
import com.google.api.generator.engine.ast.ScopeNode;
import com.google.api.generator.gapic.composer.comment.CommentComposer;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.gapic.model.GapicContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import com.google.api.generator.engine.ast.TypeNode;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.comment.StubCommentComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.gapic.model.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
import com.google.api.generator.engine.ast.ValueExpr;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.comment.StubCommentComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.gapic.model.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.gapic.model.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.gapic.model.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.google.api.generator.engine.ast.ValueExpr;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.comment.CommentComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.ResourceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
import com.google.api.generator.engine.ast.ValueExpr;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.comment.ServiceClientCommentComposer;
import com.google.api.generator.gapic.composer.samplecode.ServiceClientSampleCodeComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
Expand Down Expand Up @@ -95,6 +97,7 @@ public class ServiceClientClassComposer implements ClassComposer {

private static final Reference LIST_REFERENCE = ConcreteReference.withClazz(List.class);
private static final Reference MAP_REFERENCE = ConcreteReference.withClazz(Map.class);

private static final TypeNode OBJECTS_TYPE =
TypeNode.withReference(ConcreteReference.withClazz(Objects.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
import com.google.api.generator.engine.ast.VaporReference;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.comment.SettingsCommentComposer;
import com.google.api.generator.gapic.composer.samplecode.SettingsSampleCodeComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.gapic.model.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import com.google.api.generator.engine.ast.Statement;
import com.google.api.generator.engine.ast.ThrowExpr;
import com.google.api.generator.engine.ast.TypeNode;
import com.google.api.generator.gapic.composer.comment.StubCommentComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.gapic.model.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@
import com.google.api.generator.engine.ast.VaporReference;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.comment.SettingsCommentComposer;
import com.google.api.generator.gapic.composer.samplecode.SettingsSampleCodeComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.GapicBatchingSettings;
import com.google.api.generator.gapic.model.GapicClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@rules_java//java:defs.bzl", "java_library")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "comment_files",
srcs = glob(["*.java"]),
)

java_library(
name = "comment",
srcs = [
":comment_files",
],
deps = [
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/gapic/composer/utils",
"//src/main/java/com/google/api/generator/gapic/model",
"//src/main/java/com/google/api/generator/gapic/utils",
"@com_google_guava_guava//jar",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.generator.gapic.composer;
package com.google.api.generator.gapic.composer.comment;

import com.google.api.generator.engine.ast.BlockComment;
import com.google.api.generator.engine.ast.CommentStatement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.generator.gapic.composer;
package com.google.api.generator.gapic.composer.comment;

import com.google.api.generator.engine.ast.CommentStatement;
import com.google.api.generator.engine.ast.JavaDocComment;
import com.google.api.generator.engine.ast.TypeNode;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.Method;
import com.google.api.generator.gapic.model.MethodArgument;
import com.google.api.generator.gapic.model.Service;
Expand All @@ -29,7 +30,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

class ServiceClientCommentComposer {
public class ServiceClientCommentComposer {
// Tokens.
private static final String COLON = ":";
private static final String EMPTY_STRING = "";
Expand Down Expand Up @@ -102,12 +103,12 @@ class ServiceClientCommentComposer {
+ " should be preferred.";

// Comments.
static final CommentStatement GET_OPERATIONS_CLIENT_METHOD_COMMENT =
public static final CommentStatement GET_OPERATIONS_CLIENT_METHOD_COMMENT =
toSimpleComment(
"Returns the OperationsClient that can be used to query the status of a long-running"
+ " operation returned by another API method call.");

static List<CommentStatement> createClassHeaderComments(
public static List<CommentStatement> createClassHeaderComments(
Service service, String credentialsSampleCode, String endpointSampleCode) {
JavaDocComment.Builder classHeaderJavadocBuilder = JavaDocComment.builder();
if (service.hasDescription()) {
Expand Down Expand Up @@ -150,14 +151,14 @@ static List<CommentStatement> createClassHeaderComments(
CommentStatement.withComment(classHeaderJavadocBuilder.build()));
}

static CommentStatement createCreateMethodStubArgComment(
public static CommentStatement createCreateMethodStubArgComment(
String serviceName, TypeNode settingsType) {
return toSimpleComment(
String.format(
CREATE_METHOD_STUB_ARG_PATTERN, serviceName, settingsType.reference().name()));
}

static List<CommentStatement> createRpcMethodHeaderComment(
public static List<CommentStatement> createRpcMethodHeaderComment(
Method method, List<MethodArgument> methodArguments) {
JavaDocComment.Builder methodJavadocBuilder = JavaDocComment.builder();

Expand Down Expand Up @@ -191,23 +192,23 @@ static List<CommentStatement> createRpcMethodHeaderComment(
return comments;
}

static List<CommentStatement> createRpcMethodHeaderComment(Method method) {
public static List<CommentStatement> createRpcMethodHeaderComment(Method method) {
return createRpcMethodHeaderComment(method, Collections.emptyList());
}

static CommentStatement createMethodNoArgComment(String serviceName) {
public static CommentStatement createMethodNoArgComment(String serviceName) {
return toSimpleComment(String.format(CREATE_METHOD_NO_ARG_PATTERN, serviceName));
}

static CommentStatement createProtectedCtorSettingsArgComment(String serviceName) {
public static CommentStatement createProtectedCtorSettingsArgComment(String serviceName) {
return toSimpleComment(String.format(PROTECTED_CONSTRUCTOR_SETTINGS_ARG_PATTERN, serviceName));
}

static CommentStatement createMethodSettingsArgComment(String serviceName) {
public static CommentStatement createMethodSettingsArgComment(String serviceName) {
return toSimpleComment(String.format(CREATE_METHOD_SETTINGS_ARG_PATTERN, serviceName));
}

static List<CommentStatement> createRpcCallableMethodHeaderComment(Method method) {
public static List<CommentStatement> createRpcCallableMethodHeaderComment(Method method) {
JavaDocComment.Builder methodJavadocBuilder = JavaDocComment.builder();

if (method.hasDescription()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.generator.gapic.composer;
package com.google.api.generator.gapic.composer.comment;

import com.google.api.generator.engine.ast.CommentStatement;
import com.google.api.generator.engine.ast.JavaDocComment;
Expand All @@ -25,7 +25,7 @@
import java.util.Optional;
import java.util.stream.Collectors;

class SettingsCommentComposer {
public class SettingsCommentComposer {
private static final String COLON = ":";

private static final String STUB_PATTERN = "%sStub";
Expand Down Expand Up @@ -54,29 +54,29 @@ class SettingsCommentComposer {
private static final String CLASS_HEADER_DEFAULTS_RETRIES_DESCRIPTION =
"Retries are configured for idempotent methods but not for non-idempotent methods.";

static final CommentStatement DEFAULT_SCOPES_COMMENT =
public static final CommentStatement DEFAULT_SCOPES_COMMENT =
toSimpleComment("The default scopes of the service.");

static final CommentStatement DEFAULT_EXECUTOR_PROVIDER_BUILDER_METHOD_COMMENT =
public 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 =
public static final CommentStatement DEFAULT_SERVICE_ENDPOINT_METHOD_COMMENT =
toSimpleComment("Returns the default service endpoint.");
static final CommentStatement DEFAULT_SERVICE_SCOPES_METHOD_COMMENT =
public static final CommentStatement DEFAULT_SERVICE_SCOPES_METHOD_COMMENT =
toSimpleComment("Returns the default service scopes.");

static final CommentStatement DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT =
public 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 =
public 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 =
public static final CommentStatement NEW_BUILDER_METHOD_COMMENT =
toSimpleComment("Returns a new builder for this class.");

static final CommentStatement TO_BUILDER_METHOD_COMMENT =
public static final CommentStatement TO_BUILDER_METHOD_COMMENT =
toSimpleComment("Returns a builder containing all the values of this settings class.");

static final List<CommentStatement> APPLY_TO_ALL_UNARY_METHODS_METHOD_COMMENTS =
public static final List<CommentStatement> APPLY_TO_ALL_UNARY_METHODS_METHOD_COMMENTS =
Arrays.asList(
LineComment.withComment("NEXT_MAJOR_VER: remove 'throws Exception'."),
JavaDocComment.builder()
Expand All @@ -90,19 +90,19 @@ class SettingsCommentComposer {
.map(c -> CommentStatement.withComment(c))
.collect(Collectors.toList());

static CommentStatement createCallSettingsGetterComment(String javaMethodName) {
public static CommentStatement createCallSettingsGetterComment(String javaMethodName) {
return toSimpleComment(String.format(CALL_SETTINGS_METHOD_DOC_PATTERN, javaMethodName));
}

static CommentStatement createBuilderClassComment(String outerClassName) {
public static CommentStatement createBuilderClassComment(String outerClassName) {
return toSimpleComment(String.format(BUILDER_CLASS_DOC_PATTERN, outerClassName));
}

static CommentStatement createCallSettingsBuilderGetterComment(String javaMethodName) {
public static CommentStatement createCallSettingsBuilderGetterComment(String javaMethodName) {
return toSimpleComment(String.format(CALL_SETTINGS_BUILDER_METHOD_DOC_PATTERN, javaMethodName));
}

static List<CommentStatement> createClassHeaderComments(
public static List<CommentStatement> createClassHeaderComments(
String configuredClassName,
String defaultHost,
Optional<String> methodNameOpt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.generator.gapic.composer;
package com.google.api.generator.gapic.composer.comment;

import com.google.api.generator.engine.ast.CommentStatement;
import com.google.api.generator.engine.ast.JavaDocComment;
import java.util.Arrays;
import java.util.List;

class StubCommentComposer {
public class StubCommentComposer {
private static final String STUB_CLASS_HEADER_SUMMARY_PATTERN =
"Base stub class for the %s service API.";
private static final String GRPC_CALLABLE_FACTORY_CLASS_HEADER_SUMMARY_PATTERN =
Expand All @@ -31,7 +31,8 @@ class StubCommentComposer {
private static final String ADVANCED_USAGE_API_REFLECTION_DESCRIPTION =
"This class is for advanced usage and reflects the underlying API directly.";

static List<CommentStatement> createGrpcServiceStubClassHeaderComments(String serviceName) {
public static List<CommentStatement> createGrpcServiceStubClassHeaderComments(
String serviceName) {
return Arrays.asList(
CommentComposer.AUTO_GENERATED_CLASS_COMMENT,
CommentStatement.withComment(
Expand All @@ -41,7 +42,7 @@ static List<CommentStatement> createGrpcServiceStubClassHeaderComments(String se
.build()));
}

static List<CommentStatement> createGrpcServiceCallableFactoryClassHeaderComments(
public static List<CommentStatement> createGrpcServiceCallableFactoryClassHeaderComments(
String serviceName) {
return Arrays.asList(
CommentComposer.AUTO_GENERATED_CLASS_COMMENT,
Expand All @@ -53,7 +54,7 @@ static List<CommentStatement> createGrpcServiceCallableFactoryClassHeaderComment
.build()));
}

static List<CommentStatement> createServiceStubClassHeaderComments(String serviceName) {
public static List<CommentStatement> createServiceStubClassHeaderComments(String serviceName) {
return Arrays.asList(
CommentComposer.AUTO_GENERATED_CLASS_COMMENT,
CommentStatement.withComment(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@rules_java//java:defs.bzl", "java_library")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "utils_files",
srcs = glob(["*.java"]),
)

java_library(
name = "utils",
srcs = [
":utils_files",
],
deps = [
"//src/main/java/com/google/api/generator/gapic/model",
],
)
Loading