Skip to content

Commit b59c7e3

Browse files
authored
[ggj][codegen] fix: add back method comment for protected ctors in GrpcServiceStub (#592)
* fix: fix dep ordering in Bazel dedupe rules * fix: use lowerCamelCase param names in ServiceClient JavaDocs * fix: add HTTP's additional_bindings to GrpcServiceStub call settings * fix: add back method comment for protected ctors in GrpcServiceStub
1 parent 767d1c2 commit b59c7e3

File tree

10 files changed

+100
-0
lines changed

10 files changed

+100
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
import com.google.api.generator.engine.ast.AnonymousClassExpr;
3030
import com.google.api.generator.engine.ast.AssignmentExpr;
3131
import com.google.api.generator.engine.ast.ClassDefinition;
32+
import com.google.api.generator.engine.ast.CommentStatement;
3233
import com.google.api.generator.engine.ast.ConcreteReference;
3334
import com.google.api.generator.engine.ast.EmptyLineStatement;
3435
import com.google.api.generator.engine.ast.EnumRefExpr;
3536
import com.google.api.generator.engine.ast.Expr;
3637
import com.google.api.generator.engine.ast.ExprStatement;
38+
import com.google.api.generator.engine.ast.JavaDocComment;
3739
import com.google.api.generator.engine.ast.MethodDefinition;
3840
import com.google.api.generator.engine.ast.MethodInvocationExpr;
3941
import com.google.api.generator.engine.ast.NewObjectExpr;
@@ -525,6 +527,8 @@ private static List<MethodDefinition> createConstructorMethods(
525527
MethodDefinition.constructorBuilder()
526528
.setScope(ScopeNode.PROTECTED)
527529
.setReturnType(thisClassType)
530+
.setHeaderCommentStatements(
531+
Arrays.asList(createProtectedCtorComment(service.name())))
528532
.setArguments(
529533
args.stream()
530534
.map(v -> v.toBuilder().setIsDecl(true).build())
@@ -1143,4 +1147,14 @@ private static String getProtoRpcFullMethodName(Service protoService, Method pro
11431147
private static String getThisClassName(String serviceName) {
11441148
return String.format(CLASS_NAME_PATTERN, serviceName);
11451149
}
1150+
1151+
private static CommentStatement createProtectedCtorComment(String serviceName) {
1152+
return CommentStatement.withComment(
1153+
JavaDocComment.withComment(
1154+
String.format(
1155+
"Constructs an instance of %s, using the given settings. This is protected so that"
1156+
+ " it is easy to make a subclass, but otherwise, the static factory methods"
1157+
+ " should be preferred.",
1158+
getThisClassName(serviceName))));
1159+
}
11461160
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,19 @@ public class GrpcEchoStub extends EchoStub {
147147
return new GrpcEchoStub(EchoStubSettings.newBuilder().build(), clientContext, callableFactory);
148148
}
149149

150+
/**
151+
* Constructs an instance of GrpcEchoStub, using the given settings. This is protected so that it
152+
* is easy to make a subclass, but otherwise, the static factory methods should be preferred.
153+
*/
150154
protected GrpcEchoStub(EchoStubSettings settings, ClientContext clientContext)
151155
throws IOException {
152156
this(settings, clientContext, new GrpcEchoCallableFactory());
153157
}
154158

159+
/**
160+
* Constructs an instance of GrpcEchoStub, using the given settings. This is protected so that it
161+
* is easy to make a subclass, but otherwise, the static factory methods should be preferred.
162+
*/
155163
protected GrpcEchoStub(
156164
EchoStubSettings settings,
157165
ClientContext clientContext,

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

+10
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,21 @@ public class GrpcPublisherStub extends PublisherStub {
163163
PublisherStubSettings.newBuilder().build(), clientContext, callableFactory);
164164
}
165165

166+
/**
167+
* Constructs an instance of GrpcPublisherStub, using the given settings. This is protected so
168+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
169+
* preferred.
170+
*/
166171
protected GrpcPublisherStub(PublisherStubSettings settings, ClientContext clientContext)
167172
throws IOException {
168173
this(settings, clientContext, new GrpcPublisherCallableFactory());
169174
}
170175

176+
/**
177+
* Constructs an instance of GrpcPublisherStub, using the given settings. This is protected so
178+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
179+
* preferred.
180+
*/
171181
protected GrpcPublisherStub(
172182
PublisherStubSettings settings,
173183
ClientContext clientContext,

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

+8
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,19 @@ public class GrpcTestingStub extends TestingStub {
155155
TestingStubSettings.newBuilder().build(), clientContext, callableFactory);
156156
}
157157

158+
/**
159+
* Constructs an instance of GrpcTestingStub, using the given settings. This is protected so that
160+
* it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
161+
*/
158162
protected GrpcTestingStub(TestingStubSettings settings, ClientContext clientContext)
159163
throws IOException {
160164
this(settings, clientContext, new GrpcTestingCallableFactory());
161165
}
162166

167+
/**
168+
* Constructs an instance of GrpcTestingStub, using the given settings. This is protected so that
169+
* it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
170+
*/
163171
protected GrpcTestingStub(
164172
TestingStubSettings settings,
165173
ClientContext clientContext,

test/integration/goldens/asset/GrpcAssetServiceStub.java

+10
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,21 @@ public static final GrpcAssetServiceStub create(
182182
AssetServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
183183
}
184184

185+
/**
186+
* Constructs an instance of GrpcAssetServiceStub, using the given settings. This is protected so
187+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
188+
* preferred.
189+
*/
185190
protected GrpcAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext)
186191
throws IOException {
187192
this(settings, clientContext, new GrpcAssetServiceCallableFactory());
188193
}
189194

195+
/**
196+
* Constructs an instance of GrpcAssetServiceStub, using the given settings. This is protected so
197+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
198+
* preferred.
199+
*/
190200
protected GrpcAssetServiceStub(
191201
AssetServiceStubSettings settings,
192202
ClientContext clientContext,

test/integration/goldens/library/GrpcLibraryServiceStub.java

+10
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,21 @@ public static final GrpcLibraryServiceStub create(
186186
LibraryServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
187187
}
188188

189+
/**
190+
* Constructs an instance of GrpcLibraryServiceStub, using the given settings. This is protected
191+
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
192+
* preferred.
193+
*/
189194
protected GrpcLibraryServiceStub(LibraryServiceStubSettings settings, ClientContext clientContext)
190195
throws IOException {
191196
this(settings, clientContext, new GrpcLibraryServiceCallableFactory());
192197
}
193198

199+
/**
200+
* Constructs an instance of GrpcLibraryServiceStub, using the given settings. This is protected
201+
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
202+
* preferred.
203+
*/
194204
protected GrpcLibraryServiceStub(
195205
LibraryServiceStubSettings settings,
196206
ClientContext clientContext,

test/integration/goldens/logging/GrpcConfigServiceV2Stub.java

+10
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,21 @@ public static final GrpcConfigServiceV2Stub create(
247247
ConfigServiceV2StubSettings.newBuilder().build(), clientContext, callableFactory);
248248
}
249249

250+
/**
251+
* Constructs an instance of GrpcConfigServiceV2Stub, using the given settings. This is protected
252+
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
253+
* preferred.
254+
*/
250255
protected GrpcConfigServiceV2Stub(
251256
ConfigServiceV2StubSettings settings, ClientContext clientContext) throws IOException {
252257
this(settings, clientContext, new GrpcConfigServiceV2CallableFactory());
253258
}
254259

260+
/**
261+
* Constructs an instance of GrpcConfigServiceV2Stub, using the given settings. This is protected
262+
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
263+
* preferred.
264+
*/
255265
protected GrpcConfigServiceV2Stub(
256266
ConfigServiceV2StubSettings settings,
257267
ClientContext clientContext,

test/integration/goldens/logging/GrpcLoggingServiceV2Stub.java

+10
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,21 @@ public static final GrpcLoggingServiceV2Stub create(
146146
LoggingServiceV2StubSettings.newBuilder().build(), clientContext, callableFactory);
147147
}
148148

149+
/**
150+
* Constructs an instance of GrpcLoggingServiceV2Stub, using the given settings. This is protected
151+
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
152+
* preferred.
153+
*/
149154
protected GrpcLoggingServiceV2Stub(
150155
LoggingServiceV2StubSettings settings, ClientContext clientContext) throws IOException {
151156
this(settings, clientContext, new GrpcLoggingServiceV2CallableFactory());
152157
}
153158

159+
/**
160+
* Constructs an instance of GrpcLoggingServiceV2Stub, using the given settings. This is protected
161+
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
162+
* preferred.
163+
*/
154164
protected GrpcLoggingServiceV2Stub(
155165
LoggingServiceV2StubSettings settings,
156166
ClientContext clientContext,

test/integration/goldens/logging/GrpcMetricsServiceV2Stub.java

+10
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,21 @@ public static final GrpcMetricsServiceV2Stub create(
129129
MetricsServiceV2StubSettings.newBuilder().build(), clientContext, callableFactory);
130130
}
131131

132+
/**
133+
* Constructs an instance of GrpcMetricsServiceV2Stub, using the given settings. This is protected
134+
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
135+
* preferred.
136+
*/
132137
protected GrpcMetricsServiceV2Stub(
133138
MetricsServiceV2StubSettings settings, ClientContext clientContext) throws IOException {
134139
this(settings, clientContext, new GrpcMetricsServiceV2CallableFactory());
135140
}
136141

142+
/**
143+
* Constructs an instance of GrpcMetricsServiceV2Stub, using the given settings. This is protected
144+
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
145+
* preferred.
146+
*/
137147
protected GrpcMetricsServiceV2Stub(
138148
MetricsServiceV2StubSettings settings,
139149
ClientContext clientContext,

test/integration/goldens/redis/GrpcCloudRedisStub.java

+10
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,21 @@ public static final GrpcCloudRedisStub create(
191191
CloudRedisStubSettings.newBuilder().build(), clientContext, callableFactory);
192192
}
193193

194+
/**
195+
* Constructs an instance of GrpcCloudRedisStub, using the given settings. This is protected so
196+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
197+
* preferred.
198+
*/
194199
protected GrpcCloudRedisStub(CloudRedisStubSettings settings, ClientContext clientContext)
195200
throws IOException {
196201
this(settings, clientContext, new GrpcCloudRedisCallableFactory());
197202
}
198203

204+
/**
205+
* Constructs an instance of GrpcCloudRedisStub, using the given settings. This is protected so
206+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
207+
* preferred.
208+
*/
199209
protected GrpcCloudRedisStub(
200210
CloudRedisStubSettings settings,
201211
ClientContext clientContext,

0 commit comments

Comments
 (0)