Skip to content

Commit a4be62b

Browse files
committed
refactor(gapic): replace isClientLifecycleRelevant boolean with sampleComment property in Sample model
1 parent b9169d1 commit a4be62b

File tree

146 files changed

+666
-664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+666
-664
lines changed

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/CommentComposer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public class CommentComposer {
8686
CommentStatement.withComment(
8787
LineComment.withComment(
8888
"- The samples create a client that can be re-used for multiple requests\n"
89-
+ " and are expected to be long-lived.\n"
90-
+ " The clients should be resource managed properly and eventually closed.\n"
89+
+ " and are expected to be long-lived.\n"
90+
+ " The clients should be resource managed properly and eventually closed.\n"
9191
+ "For more information on client lifecycle, see\n"
9292
+ "https://docs.cloud.google.com/java/docs/client-lifecycle")));
9393

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/samplecode/SampleComposer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ static List<Statement> composeInlineSample(List<Statement> sampleBody) {
4343

4444
static List<Statement> composeInlineSample(Sample sample) {
4545
return bodyWithComment(
46-
sample.isClientLifecycleRelevant()
47-
? CommentComposer.AUTO_GENERATED_SAMPLE_COMMENT
48-
: CommentComposer.AUTO_GENERATED_SAMPLE_COMMENT_BASE,
46+
sample.sampleComment() != null
47+
? sample.sampleComment()
48+
: CommentComposer.AUTO_GENERATED_SAMPLE_COMMENT,
4949
sample.body());
5050
}
5151

@@ -58,9 +58,9 @@ static ClassDefinition composeExecutableSample(Sample sample, String pakkage) {
5858
sample.name(),
5959
sample.variableAssignments(),
6060
bodyWithComment(
61-
sample.isClientLifecycleRelevant()
62-
? CommentComposer.AUTO_GENERATED_SAMPLE_COMMENT
63-
: CommentComposer.AUTO_GENERATED_SAMPLE_COMMENT_BASE,
61+
sample.sampleComment() != null
62+
? sample.sampleComment()
63+
: CommentComposer.AUTO_GENERATED_SAMPLE_COMMENT,
6464
sample.body()),
6565
sample.regionTag());
6666
}

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.api.generator.engine.ast.Variable;
2727
import com.google.api.generator.engine.ast.VariableExpr;
2828
import com.google.api.generator.gapic.model.RegionTag;
29+
import com.google.api.generator.gapic.composer.comment.CommentComposer;
2930
import com.google.api.generator.gapic.model.Sample;
3031
import com.google.api.generator.gapic.utils.JavaStyle;
3132
import java.time.Duration;
@@ -247,7 +248,7 @@ public static Optional<Sample> composeSettingsSample(
247248
Sample.builder()
248249
.setBody(statements)
249250
.setRegionTag(regionTag)
250-
.setIsClientLifecycleRelevant(false)
251+
.setSampleComment(CommentComposer.AUTO_GENERATED_SAMPLE_COMMENT_BASE)
251252
.build());
252253
}
253254

@@ -443,7 +444,7 @@ public static Optional<Sample> composeLroSettingsSample(
443444
Sample.builder()
444445
.setBody(statements)
445446
.setRegionTag(regionTag)
446-
.setIsClientLifecycleRelevant(false)
447+
.setSampleComment(CommentComposer.AUTO_GENERATED_SAMPLE_COMMENT_BASE)
447448
.build());
448449
}
449450
}

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Sample.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.auto.value.AutoValue;
2121
import com.google.common.collect.ImmutableList;
2222
import java.util.List;
23+
import javax.annotation.Nullable;
2324

2425
/**
2526
* This model represents a generated code sample. It contains the information needed to generate a
@@ -39,15 +40,15 @@ public abstract class Sample {
3940

4041
public abstract boolean isCanonical();
4142

42-
public abstract boolean isClientLifecycleRelevant();
43+
@Nullable
44+
public abstract List<Statement> sampleComment();
4345

4446
public static Builder builder() {
4547
return new AutoValue_Sample.Builder()
4648
.setBody(ImmutableList.of())
4749
.setVariableAssignments(ImmutableList.of())
4850
.setFileHeader(ImmutableList.of())
49-
.setIsCanonical(false)
50-
.setIsClientLifecycleRelevant(true);
51+
.setIsCanonical(false);
5152
}
5253

5354
public abstract Builder toBuilder();
@@ -91,7 +92,7 @@ public abstract static class Builder {
9192

9293
public abstract Builder setIsCanonical(boolean isCanonical);
9394

94-
public abstract Builder setIsClientLifecycleRelevant(boolean isClientLifecycleRelevant);
95+
public abstract Builder setSampleComment(List<Statement> sampleComment);
9596

9697
abstract Builder setName(String name);
9798

sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/engine/writer/goldens/GrpcServiceClientWithNestedClassImport.golden

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import javax.annotation.Generated;
2121
* // - It may require specifying regional endpoints when creating the service client as shown in
2222
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
2323
* // - The samples create a client that can be re-used for multiple requests
24-
* // and are expected to be long-lived.
25-
* // The clients should be resource managed properly and eventually closed.
24+
* // and are expected to be long-lived.
25+
* // The clients should be resource managed properly and eventually closed.
2626
* // For more information on client lifecycle, see
2727
* // https://docs.cloud.google.com/java/docs/client-lifecycle
2828
* NestedMessageServiceClient nestedMessageServiceClient = NestedMessageServiceClient.create();
@@ -75,8 +75,8 @@ import javax.annotation.Generated;
7575
* // - It may require specifying regional endpoints when creating the service client as shown in
7676
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
7777
* // - The samples create a client that can be re-used for multiple requests
78-
* // and are expected to be long-lived.
79-
* // The clients should be resource managed properly and eventually closed.
78+
* // and are expected to be long-lived.
79+
* // The clients should be resource managed properly and eventually closed.
8080
* // For more information on client lifecycle, see
8181
* // https://docs.cloud.google.com/java/docs/client-lifecycle
8282
* NestedMessageServiceSettings nestedMessageServiceSettings =
@@ -96,8 +96,8 @@ import javax.annotation.Generated;
9696
* // - It may require specifying regional endpoints when creating the service client as shown in
9797
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
9898
* // - The samples create a client that can be re-used for multiple requests
99-
* // and are expected to be long-lived.
100-
* // The clients should be resource managed properly and eventually closed.
99+
* // and are expected to be long-lived.
100+
* // The clients should be resource managed properly and eventually closed.
101101
* // For more information on client lifecycle, see
102102
* // https://docs.cloud.google.com/java/docs/client-lifecycle
103103
* NestedMessageServiceSettings nestedMessageServiceSettings =
@@ -169,8 +169,8 @@ public class NestedMessageServiceClient implements BackgroundResource {
169169
* // - It may require specifying regional endpoints when creating the service client as shown in
170170
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
171171
* // - The samples create a client that can be re-used for multiple requests
172-
* // and are expected to be long-lived.
173-
* // The clients should be resource managed properly and eventually closed.
172+
* // and are expected to be long-lived.
173+
* // The clients should be resource managed properly and eventually closed.
174174
* // For more information on client lifecycle, see
175175
* // https://docs.cloud.google.com/java/docs/client-lifecycle
176176
* NestedMessageServiceClient nestedMessageServiceClient = NestedMessageServiceClient.create();
@@ -196,8 +196,8 @@ public class NestedMessageServiceClient implements BackgroundResource {
196196
* // - It may require specifying regional endpoints when creating the service client as shown in
197197
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
198198
* // - The samples create a client that can be re-used for multiple requests
199-
* // and are expected to be long-lived.
200-
* // The clients should be resource managed properly and eventually closed.
199+
* // and are expected to be long-lived.
200+
* // The clients should be resource managed properly and eventually closed.
201201
* // For more information on client lifecycle, see
202202
* // https://docs.cloud.google.com/java/docs/client-lifecycle
203203
* NestedMessageServiceClient nestedMessageServiceClient = NestedMessageServiceClient.create();

sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/goldens/ShowcaseWithEchoPackageInfo.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* // - It may require specifying regional endpoints when creating the service client as shown in
1818
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
1919
* // - The samples create a client that can be re-used for multiple requests
20-
* // and are expected to be long-lived.
21-
* // The clients should be resource managed properly and eventually closed.
20+
* // and are expected to be long-lived.
21+
* // The clients should be resource managed properly and eventually closed.
2222
* // For more information on client lifecycle, see
2323
* // https://docs.cloud.google.com/java/docs/client-lifecycle
2424
* EchoClient echoClient = EchoClient.create();

sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/BookshopClient.golden

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import javax.annotation.Generated;
2222
* // - It may require specifying regional endpoints when creating the service client as shown in
2323
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
2424
* // - The samples create a client that can be re-used for multiple requests
25-
* // and are expected to be long-lived.
26-
* // The clients should be resource managed properly and eventually closed.
25+
* // and are expected to be long-lived.
26+
* // The clients should be resource managed properly and eventually closed.
2727
* // For more information on client lifecycle, see
2828
* // https://docs.cloud.google.com/java/docs/client-lifecycle
2929
* BookshopClient bookshopClient = BookshopClient.create();
@@ -81,8 +81,8 @@ import javax.annotation.Generated;
8181
* // - It may require specifying regional endpoints when creating the service client as shown in
8282
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
8383
* // - The samples create a client that can be re-used for multiple requests
84-
* // and are expected to be long-lived.
85-
* // The clients should be resource managed properly and eventually closed.
84+
* // and are expected to be long-lived.
85+
* // The clients should be resource managed properly and eventually closed.
8686
* // For more information on client lifecycle, see
8787
* // https://docs.cloud.google.com/java/docs/client-lifecycle
8888
* BookshopSettings bookshopSettings =
@@ -101,8 +101,8 @@ import javax.annotation.Generated;
101101
* // - It may require specifying regional endpoints when creating the service client as shown in
102102
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
103103
* // - The samples create a client that can be re-used for multiple requests
104-
* // and are expected to be long-lived.
105-
* // The clients should be resource managed properly and eventually closed.
104+
* // and are expected to be long-lived.
105+
* // The clients should be resource managed properly and eventually closed.
106106
* // For more information on client lifecycle, see
107107
* // https://docs.cloud.google.com/java/docs/client-lifecycle
108108
* BookshopSettings bookshopSettings =
@@ -172,8 +172,8 @@ public class BookshopClient implements BackgroundResource {
172172
* // - It may require specifying regional endpoints when creating the service client as shown in
173173
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
174174
* // - The samples create a client that can be re-used for multiple requests
175-
* // and are expected to be long-lived.
176-
* // The clients should be resource managed properly and eventually closed.
175+
* // and are expected to be long-lived.
176+
* // The clients should be resource managed properly and eventually closed.
177177
* // For more information on client lifecycle, see
178178
* // https://docs.cloud.google.com/java/docs/client-lifecycle
179179
* BookshopClient bookshopClient = BookshopClient.create();
@@ -203,8 +203,8 @@ public class BookshopClient implements BackgroundResource {
203203
* // - It may require specifying regional endpoints when creating the service client as shown in
204204
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
205205
* // - The samples create a client that can be re-used for multiple requests
206-
* // and are expected to be long-lived.
207-
* // The clients should be resource managed properly and eventually closed.
206+
* // and are expected to be long-lived.
207+
* // The clients should be resource managed properly and eventually closed.
208208
* // For more information on client lifecycle, see
209209
* // https://docs.cloud.google.com/java/docs/client-lifecycle
210210
* BookshopClient bookshopClient = BookshopClient.create();
@@ -234,8 +234,8 @@ public class BookshopClient implements BackgroundResource {
234234
* // - It may require specifying regional endpoints when creating the service client as shown in
235235
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
236236
* // - The samples create a client that can be re-used for multiple requests
237-
* // and are expected to be long-lived.
238-
* // The clients should be resource managed properly and eventually closed.
237+
* // and are expected to be long-lived.
238+
* // The clients should be resource managed properly and eventually closed.
239239
* // For more information on client lifecycle, see
240240
* // https://docs.cloud.google.com/java/docs/client-lifecycle
241241
* BookshopClient bookshopClient = BookshopClient.create();
@@ -266,8 +266,8 @@ public class BookshopClient implements BackgroundResource {
266266
* // - It may require specifying regional endpoints when creating the service client as shown in
267267
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
268268
* // - The samples create a client that can be re-used for multiple requests
269-
* // and are expected to be long-lived.
270-
* // The clients should be resource managed properly and eventually closed.
269+
* // and are expected to be long-lived.
270+
* // The clients should be resource managed properly and eventually closed.
271271
* // For more information on client lifecycle, see
272272
* // https://docs.cloud.google.com/java/docs/client-lifecycle
273273
* BookshopClient bookshopClient = BookshopClient.create();

sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/DeprecatedServiceClient.golden

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import javax.annotation.Generated;
2121
* // - It may require specifying regional endpoints when creating the service client as shown in
2222
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
2323
* // - The samples create a client that can be re-used for multiple requests
24-
* // and are expected to be long-lived.
25-
* // The clients should be resource managed properly and eventually closed.
24+
* // and are expected to be long-lived.
25+
* // The clients should be resource managed properly and eventually closed.
2626
* // For more information on client lifecycle, see
2727
* // https://docs.cloud.google.com/java/docs/client-lifecycle
2828
* DeprecatedServiceClient deprecatedServiceClient = DeprecatedServiceClient.create();
@@ -89,8 +89,8 @@ import javax.annotation.Generated;
8989
* // - It may require specifying regional endpoints when creating the service client as shown in
9090
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
9191
* // - The samples create a client that can be re-used for multiple requests
92-
* // and are expected to be long-lived.
93-
* // The clients should be resource managed properly and eventually closed.
92+
* // and are expected to be long-lived.
93+
* // The clients should be resource managed properly and eventually closed.
9494
* // For more information on client lifecycle, see
9595
* // https://docs.cloud.google.com/java/docs/client-lifecycle
9696
* DeprecatedServiceSettings deprecatedServiceSettings =
@@ -110,8 +110,8 @@ import javax.annotation.Generated;
110110
* // - It may require specifying regional endpoints when creating the service client as shown in
111111
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
112112
* // - The samples create a client that can be re-used for multiple requests
113-
* // and are expected to be long-lived.
114-
* // The clients should be resource managed properly and eventually closed.
113+
* // and are expected to be long-lived.
114+
* // The clients should be resource managed properly and eventually closed.
115115
* // For more information on client lifecycle, see
116116
* // https://docs.cloud.google.com/java/docs/client-lifecycle
117117
* DeprecatedServiceSettings deprecatedServiceSettings =
@@ -186,8 +186,8 @@ public class DeprecatedServiceClient implements BackgroundResource {
186186
* // - It may require specifying regional endpoints when creating the service client as shown in
187187
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
188188
* // - The samples create a client that can be re-used for multiple requests
189-
* // and are expected to be long-lived.
190-
* // The clients should be resource managed properly and eventually closed.
189+
* // and are expected to be long-lived.
190+
* // The clients should be resource managed properly and eventually closed.
191191
* // For more information on client lifecycle, see
192192
* // https://docs.cloud.google.com/java/docs/client-lifecycle
193193
* DeprecatedServiceClient deprecatedServiceClient = DeprecatedServiceClient.create();
@@ -213,8 +213,8 @@ public class DeprecatedServiceClient implements BackgroundResource {
213213
* // - It may require specifying regional endpoints when creating the service client as shown in
214214
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
215215
* // - The samples create a client that can be re-used for multiple requests
216-
* // and are expected to be long-lived.
217-
* // The clients should be resource managed properly and eventually closed.
216+
* // and are expected to be long-lived.
217+
* // The clients should be resource managed properly and eventually closed.
218218
* // For more information on client lifecycle, see
219219
* // https://docs.cloud.google.com/java/docs/client-lifecycle
220220
* DeprecatedServiceClient deprecatedServiceClient = DeprecatedServiceClient.create();
@@ -239,8 +239,8 @@ public class DeprecatedServiceClient implements BackgroundResource {
239239
* // - It may require specifying regional endpoints when creating the service client as shown in
240240
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
241241
* // - The samples create a client that can be re-used for multiple requests
242-
* // and are expected to be long-lived.
243-
* // The clients should be resource managed properly and eventually closed.
242+
* // and are expected to be long-lived.
243+
* // The clients should be resource managed properly and eventually closed.
244244
* // For more information on client lifecycle, see
245245
* // https://docs.cloud.google.com/java/docs/client-lifecycle
246246
* DeprecatedServiceClient deprecatedServiceClient = DeprecatedServiceClient.create();
@@ -268,8 +268,8 @@ public class DeprecatedServiceClient implements BackgroundResource {
268268
* // - It may require specifying regional endpoints when creating the service client as shown in
269269
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
270270
* // - The samples create a client that can be re-used for multiple requests
271-
* // and are expected to be long-lived.
272-
* // The clients should be resource managed properly and eventually closed.
271+
* // and are expected to be long-lived.
272+
* // The clients should be resource managed properly and eventually closed.
273273
* // For more information on client lifecycle, see
274274
* // https://docs.cloud.google.com/java/docs/client-lifecycle
275275
* DeprecatedServiceClient deprecatedServiceClient = DeprecatedServiceClient.create();

0 commit comments

Comments
 (0)