Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

Commit 3ca2534

Browse files
authored
fix: Use service name in ServiceClient codegen comments (#417)
1 parent 11bde65 commit 3ca2534

3 files changed

Lines changed: 39 additions & 26 deletions

File tree

src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ private static List<MethodDefinition> createStaticCreatorMethods(
223223

224224
MethodDefinition createMethodOne =
225225
MethodDefinition.builder()
226-
.setHeaderCommentStatements(ServiceClientCommentComposer.CREATE_METHOD_NO_ARG_COMMENT)
226+
.setHeaderCommentStatements(
227+
ServiceClientCommentComposer.createMethodNoArgComment(service.name()))
227228
.setScope(ScopeNode.PUBLIC)
228229
.setIsStatic(true)
229230
.setIsFinal(true)
@@ -242,7 +243,7 @@ private static List<MethodDefinition> createStaticCreatorMethods(
242243
methods.add(
243244
MethodDefinition.builder()
244245
.setHeaderCommentStatements(
245-
ServiceClientCommentComposer.CREATE_METHOD_SETTINGS_ARG_COMMENT)
246+
ServiceClientCommentComposer.createMethodSettingsArgComment(service.name()))
246247
.setScope(ScopeNode.PUBLIC)
247248
.setIsStatic(true)
248249
.setIsFinal(true)
@@ -274,7 +275,7 @@ private static List<MethodDefinition> createStaticCreatorMethods(
274275
MethodDefinition.builder()
275276
.setHeaderCommentStatements(
276277
ServiceClientCommentComposer.createCreateMethodStubArgComment(
277-
settingsVarExpr.type()))
278+
service.name(), settingsVarExpr.type()))
278279
.setAnnotations(Arrays.asList(betaAnnotation))
279280
.setScope(ScopeNode.PUBLIC)
280281
.setIsStatic(true)
@@ -365,7 +366,7 @@ private static List<MethodDefinition> createConstructorMethods(
365366
methods.add(
366367
MethodDefinition.constructorBuilder()
367368
.setHeaderCommentStatements(
368-
ServiceClientCommentComposer.PROTECTED_CONSTRUCTOR_SETTINGS_ARG_COMMENT)
369+
ServiceClientCommentComposer.createProtectedCtorSettingsArgComment(service.name()))
369370
.setScope(ScopeNode.PROTECTED)
370371
.setReturnType(thisClassType)
371372
.setArguments(settingsVarExpr.toBuilder().setIsDecl(true).build())

src/main/java/com/google/api/generator/gapic/composer/ServiceClientCommentComposer.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ServiceClientCommentComposer {
7171

7272
// Patterns.
7373
private static final String CREATE_METHOD_STUB_ARG_PATTERN =
74-
"Constructs an instance of EchoClient, using the given stub for making calls. This is for"
74+
"Constructs an instance of %sClient, using the given stub for making calls. This is for"
7575
+ " advanced usage - prefer using create(%s).";
7676

7777
private static final String SERVICE_DESCRIPTION_CUSTOMIZE_SUMMARY_PATTERN =
@@ -80,22 +80,20 @@ class ServiceClientCommentComposer {
8080

8181
private static final String SERVICE_DESCRIPTION_SUMMARY_PATTERN = "Service Description: %s";
8282

83-
// Comments.
84-
static final CommentStatement CREATE_METHOD_NO_ARG_COMMENT =
85-
toSimpleComment("Constructs an instance of EchoClient with default settings.");
83+
private static final String CREATE_METHOD_NO_ARG_PATTERN =
84+
"Constructs an instance of %sClient with default settings.";
8685

87-
static final CommentStatement CREATE_METHOD_SETTINGS_ARG_COMMENT =
88-
toSimpleComment(
89-
"Constructs an instance of EchoClient, using the given settings. The channels are"
90-
+ " created based on the settings passed in, or defaults for any settings that are"
91-
+ " not set.");
86+
private static final String CREATE_METHOD_SETTINGS_ARG_PATTERN =
87+
"Constructs an instance of %sClient, using the given settings. The channels are"
88+
+ " created based on the settings passed in, or defaults for any settings that are"
89+
+ " not set.";
9290

93-
static final CommentStatement PROTECTED_CONSTRUCTOR_SETTINGS_ARG_COMMENT =
94-
toSimpleComment(
95-
"Constructs an instance of EchoClient, using the given settings. This is protected so"
96-
+ " that it is easy to make a subclass, but otherwise, the static factory methods"
97-
+ " should be preferred.");
91+
private static final String PROTECTED_CONSTRUCTOR_SETTINGS_ARG_PATTERN =
92+
"Constructs an instance of %sClient, using the given settings. This is protected so"
93+
+ " that it is easy to make a subclass, but otherwise, the static factory methods"
94+
+ " should be preferred.";
9895

96+
// Comments.
9997
static final CommentStatement GET_OPERATIONS_CLIENT_METHOD_COMMENT =
10098
toSimpleComment(
10199
"Returns the OperationsClient that can be used to query the status of a long-running"
@@ -136,9 +134,11 @@ static List<CommentStatement> createClassHeaderComments(Service service) {
136134
CommentStatement.withComment(classHeaderJavadocBuilder.build()));
137135
}
138136

139-
static CommentStatement createCreateMethodStubArgComment(TypeNode settingsType) {
137+
static CommentStatement createCreateMethodStubArgComment(
138+
String serviceName, TypeNode settingsType) {
140139
return toSimpleComment(
141-
String.format(CREATE_METHOD_STUB_ARG_PATTERN, settingsType.reference().name()));
140+
String.format(
141+
CREATE_METHOD_STUB_ARG_PATTERN, serviceName, settingsType.reference().name()));
142142
}
143143

144144
static List<CommentStatement> createRpcMethodHeaderComment(
@@ -174,6 +174,18 @@ static List<CommentStatement> createRpcMethodHeaderComment(Method method) {
174174
return createRpcMethodHeaderComment(method, Collections.emptyList());
175175
}
176176

177+
static CommentStatement createMethodNoArgComment(String serviceName) {
178+
return toSimpleComment(String.format(CREATE_METHOD_NO_ARG_PATTERN, serviceName));
179+
}
180+
181+
static CommentStatement createProtectedCtorSettingsArgComment(String serviceName) {
182+
return toSimpleComment(String.format(PROTECTED_CONSTRUCTOR_SETTINGS_ARG_PATTERN, serviceName));
183+
}
184+
185+
static CommentStatement createMethodSettingsArgComment(String serviceName) {
186+
return toSimpleComment(String.format(CREATE_METHOD_SETTINGS_ARG_PATTERN, serviceName));
187+
}
188+
177189
static List<CommentStatement> createRpcCallableMethodHeaderComment(Method method) {
178190
JavaDocComment.Builder methodJavadocBuilder = JavaDocComment.builder();
179191

src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ public class IdentityClient implements BackgroundResource {
6161
private final IdentitySettings settings;
6262
private final IdentityStub stub;
6363

64-
/** Constructs an instance of EchoClient with default settings. */
64+
/** Constructs an instance of IdentityClient with default settings. */
6565
public static final IdentityClient create() throws IOException {
6666
return create(IdentitySettings.newBuilder().build());
6767
}
6868

6969
/**
70-
* Constructs an instance of EchoClient, using the given settings. The channels are created based
71-
* on the settings passed in, or defaults for any settings that are not set.
70+
* Constructs an instance of IdentityClient, using the given settings. The channels are created
71+
* based on the settings passed in, or defaults for any settings that are not set.
7272
*/
7373
public static final IdentityClient create(IdentitySettings settings) throws IOException {
7474
return new IdentityClient(settings);
7575
}
7676

7777
/**
78-
* Constructs an instance of EchoClient, using the given stub for making calls. This is for
78+
* Constructs an instance of IdentityClient, using the given stub for making calls. This is for
7979
* advanced usage - prefer using create(IdentitySettings).
8080
*/
8181
@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
@@ -84,8 +84,8 @@ public class IdentityClient implements BackgroundResource {
8484
}
8585

8686
/**
87-
* Constructs an instance of EchoClient, using the given settings. This is protected so that it is
88-
* easy to make a subclass, but otherwise, the static factory methods should be preferred.
87+
* Constructs an instance of IdentityClient, using the given settings. This is protected so that
88+
* it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
8989
*/
9090
protected IdentityClient(IdentitySettings settings) throws IOException {
9191
this.settings = settings;

0 commit comments

Comments
 (0)