diff --git a/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientSampleCodeComposer.java b/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientSampleCodeComposer.java index 1045275b5a..8fb4021490 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientSampleCodeComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientSampleCodeComposer.java @@ -592,18 +592,15 @@ public static String composeRegularCallableMethodHeaderSampleCode( .setValueExpr(requestBuilderExpr) .build(); - List bodyExprs = new ArrayList<>(); - bodyExprs.add(requestAssignmentExpr); - List bodyStatements = new ArrayList<>(); + bodyStatements.add(ExprStatement.withExpr(requestAssignmentExpr)); if (method.isPaged()) { bodyStatements.addAll( composePagedCallableBodyStatements(method, clientVarExpr, requestVarExpr, messageTypes)); } else { bodyStatements.addAll( - composeUnaryOrLroCallableBodyStatements( - method, clientVarExpr, requestVarExpr, bodyExprs)); + composeUnaryOrLroCallableBodyStatements(method, clientVarExpr, requestVarExpr)); } return SampleCodeWriter.write( @@ -1061,10 +1058,7 @@ private static List composeStreamClientBodyStatements( } private static List composeUnaryOrLroCallableBodyStatements( - Method method, - VariableExpr clientVarExpr, - VariableExpr requestVarExpr, - List bodyExprs) { + Method method, VariableExpr clientVarExpr, VariableExpr requestVarExpr) { List bodyStatements = new ArrayList<>(); // Create api future variable expression, and assign it with a value by invoking callable // method. @@ -1098,10 +1092,7 @@ private static List composeUnaryOrLroCallableBodyStatements( .setVariableExpr(apiFutureVarExpr.toBuilder().setIsDecl(true).build()) .setValueExpr(callableMethodInvocationExpr) .build(); - bodyExprs.add(futureAssignmentExpr); - bodyStatements.addAll( - bodyExprs.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList())); - bodyExprs.clear(); + bodyStatements.add(ExprStatement.withExpr(futureAssignmentExpr)); bodyStatements.add(CommentStatement.withComment(LineComment.withComment("Do something."))); MethodInvocationExpr getMethodInvocationExpr = diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden index 4f8aa3c1ed..5791d9086d 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden @@ -516,6 +516,12 @@ public class EchoClient implements BackgroundResource { * *
{@code
    * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandRequest request =
+   *       PagedExpandRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
    *   while (true) {
    *     PagedExpandResponse response = echoClient.pagedExpandCallable().call(request);
    *     for (EchoResponse element : response.getResponsesList()) {
@@ -612,6 +618,12 @@ public class EchoClient implements BackgroundResource {
    *
    * 
{@code
    * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandRequest request =
+   *       PagedExpandRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
    *   while (true) {
    *     PagedExpandResponse response = echoClient.simplePagedExpandCallable().call(request);
    *     for (EchoResponse element : response.getResponsesList()) {
diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden
index 16c35c6b11..2081b3bd1c 100644
--- a/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden
+++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden
@@ -580,6 +580,11 @@ public class IdentityClient implements BackgroundResource {
    *
    * 
{@code
    * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   ListUsersRequest request =
+   *       ListUsersRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
    *   while (true) {
    *     ListUsersResponse response = identityClient.listUsersCallable().call(request);
    *     for (User element : response.getResponsesList()) {
diff --git a/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientSampleCodeComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientSampleCodeComposerTest.java
index fbfc42dec0..85cabb5fc1 100644
--- a/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientSampleCodeComposerTest.java
+++ b/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientSampleCodeComposerTest.java
@@ -2452,6 +2452,12 @@ public void validComposeRegularCallableMethodHeaderSampleCode_pageRpc() {
     String expected =
         LineFormatter.lines(
             "try (EchoClient echoClient = EchoClient.create()) {\n",
+            "  PagedExpandRequest request =\n",
+            "      PagedExpandRequest.newBuilder()\n",
+            "          .setContent(\"content951530617\")\n",
+            "          .setPageSize(883849137)\n",
+            "          .setPageToken(\"pageToken873572522\")\n",
+            "          .build();\n",
             "  while (true) {\n",
             "    PagedExpandResponse response = echoClient.pagedExpandCallable().call(request);\n",
             "    for (EchoResponse element : response.getResponsesList()) {\n",
diff --git a/test/integration/goldens/asset/AssetServiceClient.java b/test/integration/goldens/asset/AssetServiceClient.java
index fa2da63b40..f1bbf06c9f 100644
--- a/test/integration/goldens/asset/AssetServiceClient.java
+++ b/test/integration/goldens/asset/AssetServiceClient.java
@@ -882,6 +882,15 @@ public final SearchAllResourcesPagedResponse searchAllResources(
    *
    * 
{@code
    * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   SearchAllResourcesRequest request =
+   *       SearchAllResourcesRequest.newBuilder()
+   *           .setScope("scope109264468")
+   *           .setQuery("query107944136")
+   *           .addAllAssetTypes(new ArrayList())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .setOrderBy("orderBy-1207110587")
+   *           .build();
    *   while (true) {
    *     SearchAllResourcesResponse response =
    *         assetServiceClient.searchAllResourcesCallable().call(request);
@@ -1039,6 +1048,13 @@ public final SearchAllIamPoliciesPagedResponse searchAllIamPolicies(
    *
    * 
{@code
    * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   SearchAllIamPoliciesRequest request =
+   *       SearchAllIamPoliciesRequest.newBuilder()
+   *           .setScope("scope109264468")
+   *           .setQuery("query107944136")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
    *   while (true) {
    *     SearchAllIamPoliciesResponse response =
    *         assetServiceClient.searchAllIamPoliciesCallable().call(request);
diff --git a/test/integration/goldens/kms/KeyManagementServiceClient.java b/test/integration/goldens/kms/KeyManagementServiceClient.java
index 5144fc1aba..3a09f649ee 100644
--- a/test/integration/goldens/kms/KeyManagementServiceClient.java
+++ b/test/integration/goldens/kms/KeyManagementServiceClient.java
@@ -295,6 +295,14 @@ public final ListKeyRingsPagedResponse listKeyRings(ListKeyRingsRequest request)
    * 
{@code
    * try (KeyManagementServiceClient keyManagementServiceClient =
    *     KeyManagementServiceClient.create()) {
+   *   ListKeyRingsRequest request =
+   *       ListKeyRingsRequest.newBuilder()
+   *           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .setFilter("filter-1274492040")
+   *           .setOrderBy("orderBy-1207110587")
+   *           .build();
    *   while (true) {
    *     ListKeyRingsResponse response =
    *         keyManagementServiceClient.listKeyRingsCallable().call(request);
@@ -438,6 +446,14 @@ public final ListCryptoKeysPagedResponse listCryptoKeys(ListCryptoKeysRequest re
    * 
{@code
    * try (KeyManagementServiceClient keyManagementServiceClient =
    *     KeyManagementServiceClient.create()) {
+   *   ListCryptoKeysRequest request =
+   *       ListCryptoKeysRequest.newBuilder()
+   *           .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .setFilter("filter-1274492040")
+   *           .setOrderBy("orderBy-1207110587")
+   *           .build();
    *   while (true) {
    *     ListCryptoKeysResponse response =
    *         keyManagementServiceClient.listCryptoKeysCallable().call(request);
@@ -593,6 +609,16 @@ public final ListCryptoKeyVersionsPagedResponse listCryptoKeyVersions(
    * 
{@code
    * try (KeyManagementServiceClient keyManagementServiceClient =
    *     KeyManagementServiceClient.create()) {
+   *   ListCryptoKeyVersionsRequest request =
+   *       ListCryptoKeyVersionsRequest.newBuilder()
+   *           .setParent(
+   *               CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
+   *                   .toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .setFilter("filter-1274492040")
+   *           .setOrderBy("orderBy-1207110587")
+   *           .build();
    *   while (true) {
    *     ListCryptoKeyVersionsResponse response =
    *         keyManagementServiceClient.listCryptoKeyVersionsCallable().call(request);
@@ -737,6 +763,14 @@ public final ListImportJobsPagedResponse listImportJobs(ListImportJobsRequest re
    * 
{@code
    * try (KeyManagementServiceClient keyManagementServiceClient =
    *     KeyManagementServiceClient.create()) {
+   *   ListImportJobsRequest request =
+   *       ListImportJobsRequest.newBuilder()
+   *           .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .setFilter("filter-1274492040")
+   *           .setOrderBy("orderBy-1207110587")
+   *           .build();
    *   while (true) {
    *     ListImportJobsResponse response =
    *         keyManagementServiceClient.listImportJobsCallable().call(request);
diff --git a/test/integration/goldens/library/LibraryServiceClient.java b/test/integration/goldens/library/LibraryServiceClient.java
index 034be02c2b..a1dad2c9c7 100644
--- a/test/integration/goldens/library/LibraryServiceClient.java
+++ b/test/integration/goldens/library/LibraryServiceClient.java
@@ -379,6 +379,11 @@ public final ListShelvesPagedResponse listShelves(ListShelvesRequest request) {
    *
    * 
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ListShelvesRequest request =
+   *       ListShelvesRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
    *   while (true) {
    *     ListShelvesResponse response = libraryServiceClient.listShelvesCallable().call(request);
    *     for (Shelf element : response.getResponsesList()) {
@@ -959,6 +964,12 @@ public final UnaryCallable listBooksPa
    *
    * 
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ListBooksRequest request =
+   *       ListBooksRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
    *   while (true) {
    *     ListBooksResponse response = libraryServiceClient.listBooksCallable().call(request);
    *     for (Book element : response.getResponsesList()) {
diff --git a/test/integration/goldens/logging/ConfigClient.java b/test/integration/goldens/logging/ConfigClient.java
index 014c6c3883..2ac4343fd8 100644
--- a/test/integration/goldens/logging/ConfigClient.java
+++ b/test/integration/goldens/logging/ConfigClient.java
@@ -419,6 +419,14 @@ public final ListBucketsPagedResponse listBuckets(ListBucketsRequest request) {
    *
    * 
{@code
    * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ListBucketsRequest request =
+   *       ListBucketsRequest.newBuilder()
+   *           .setParent(
+   *               LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]")
+   *                   .toString())
+   *           .setPageToken("pageToken873572522")
+   *           .setPageSize(883849137)
+   *           .build();
    *   while (true) {
    *     ListBucketsResponse response = configClient.listBucketsCallable().call(request);
    *     for (LogBucket element : response.getResponsesList()) {
@@ -800,6 +808,12 @@ public final UnaryCallable listViewsPa
    *
    * 
{@code
    * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ListViewsRequest request =
+   *       ListViewsRequest.newBuilder()
+   *           .setParent("parent-995424086")
+   *           .setPageToken("pageToken873572522")
+   *           .setPageSize(883849137)
+   *           .build();
    *   while (true) {
    *     ListViewsResponse response = configClient.listViewsCallable().call(request);
    *     for (LogView element : response.getResponsesList()) {
@@ -1211,6 +1225,12 @@ public final UnaryCallable listSinksPa
    *
    * 
{@code
    * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ListSinksRequest request =
+   *       ListSinksRequest.newBuilder()
+   *           .setParent(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString())
+   *           .setPageToken("pageToken873572522")
+   *           .setPageSize(883849137)
+   *           .build();
    *   while (true) {
    *     ListSinksResponse response = configClient.listSinksCallable().call(request);
    *     for (LogSink element : response.getResponsesList()) {
@@ -2091,6 +2111,13 @@ public final ListExclusionsPagedResponse listExclusions(ListExclusionsRequest re
    *
    * 
{@code
    * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ListExclusionsRequest request =
+   *       ListExclusionsRequest.newBuilder()
+   *           .setParent(
+   *               LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString())
+   *           .setPageToken("pageToken873572522")
+   *           .setPageSize(883849137)
+   *           .build();
    *   while (true) {
    *     ListExclusionsResponse response = configClient.listExclusionsCallable().call(request);
    *     for (LogExclusion element : response.getResponsesList()) {
diff --git a/test/integration/goldens/logging/LoggingClient.java b/test/integration/goldens/logging/LoggingClient.java
index cc51eabac2..66f7afcda2 100644
--- a/test/integration/goldens/logging/LoggingClient.java
+++ b/test/integration/goldens/logging/LoggingClient.java
@@ -613,6 +613,14 @@ public final ListLogEntriesPagedResponse listLogEntries(ListLogEntriesRequest re
    *
    * 
{@code
    * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   ListLogEntriesRequest request =
+   *       ListLogEntriesRequest.newBuilder()
+   *           .addAllResourceNames(new ArrayList())
+   *           .setFilter("filter-1274492040")
+   *           .setOrderBy("orderBy-1207110587")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
    *   while (true) {
    *     ListLogEntriesResponse response = loggingClient.listLogEntriesCallable().call(request);
    *     for (LogEntry element : response.getResponsesList()) {
@@ -697,6 +705,11 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource
    *
    * 
{@code
    * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   ListMonitoredResourceDescriptorsRequest request =
+   *       ListMonitoredResourceDescriptorsRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
    *   while (true) {
    *     ListMonitoredResourceDescriptorsResponse response =
    *         loggingClient.listMonitoredResourceDescriptorsCallable().call(request);
@@ -919,6 +932,13 @@ public final UnaryCallable listLogsPaged
    *
    * 
{@code
    * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   ListLogsRequest request =
+   *       ListLogsRequest.newBuilder()
+   *           .setParent(LogName.ofProjectLogName("[PROJECT]", "[LOG]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .addAllResourceNames(new ArrayList())
+   *           .build();
    *   while (true) {
    *     ListLogsResponse response = loggingClient.listLogsCallable().call(request);
    *     for (String element : response.getResponsesList()) {
diff --git a/test/integration/goldens/logging/MetricsClient.java b/test/integration/goldens/logging/MetricsClient.java
index 7c498fe19a..987083a264 100644
--- a/test/integration/goldens/logging/MetricsClient.java
+++ b/test/integration/goldens/logging/MetricsClient.java
@@ -267,6 +267,12 @@ public final ListLogMetricsPagedResponse listLogMetrics(ListLogMetricsRequest re
    *
    * 
{@code
    * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   ListLogMetricsRequest request =
+   *       ListLogMetricsRequest.newBuilder()
+   *           .setParent(ProjectName.of("[PROJECT]").toString())
+   *           .setPageToken("pageToken873572522")
+   *           .setPageSize(883849137)
+   *           .build();
    *   while (true) {
    *     ListLogMetricsResponse response = metricsClient.listLogMetricsCallable().call(request);
    *     for (LogMetric element : response.getResponsesList()) {
diff --git a/test/integration/goldens/redis/CloudRedisClient.java b/test/integration/goldens/redis/CloudRedisClient.java
index d38744c12f..f62dcd329d 100644
--- a/test/integration/goldens/redis/CloudRedisClient.java
+++ b/test/integration/goldens/redis/CloudRedisClient.java
@@ -347,6 +347,12 @@ public final ListInstancesPagedResponse listInstances(ListInstancesRequest reque
    *
    * 
{@code
    * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   ListInstancesRequest request =
+   *       ListInstancesRequest.newBuilder()
+   *           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
    *   while (true) {
    *     ListInstancesResponse response = cloudRedisClient.listInstancesCallable().call(request);
    *     for (Instance element : response.getResponsesList()) {