Skip to content

Commit

Permalink
rebase change clientType to client variable expr
Browse files Browse the repository at this point in the history
  • Loading branch information
summer-ji-eng committed Nov 20, 2020
1 parent 14cbbd3 commit 51a0cbf
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private static TryCatchStatement composePagedUnaryRpcMethodSampleCode(
TypeNode clientType,
Map<String, ResourceName> resourceNames) {
// TODO(summerji): Add unit test.
VariableExpr clientVarExpr = createVariableExpr(getClientName(clientType), clientType);
// Assign each method arguments with default value.
List<Statement> bodyStatements =
arguments.stream()
Expand All @@ -127,16 +128,17 @@ private static TryCatchStatement composePagedUnaryRpcMethodSampleCode(
.collect(Collectors.toList());
// For loop client on iterateAll method.
// e.g. for (LoggingServiceV2Client loggingServiceV2Client :
// loggingServiceV2Client.ListLogs(parent).iterateAll()) {
// //doThingsWith(element);}
// loggingServiceV2Client.ListLogs(parent).iterateAll()) {
// //doThingsWith(element);
// }
bodyStatements.add(
ForStatement.builder()
.setLocalVariableExpr(createVariableDeclExpr(getClientName(clientType), clientType))
.setCollectionExpr(createIteratorAllMethodExpr(method, clientType, arguments))
.setLocalVariableExpr(clientVarExpr.toBuilder().setIsDecl(true).build())
.setCollectionExpr(createIteratorAllMethodExpr(method, clientVarExpr, arguments))
.setBody(Arrays.asList(createLineCommentStatement("doThingsWith(element);")))
.build());
return TryCatchStatement.builder()
.setTryResourceExpr(assignClientVariableWithCreateMethodExpr(clientType))
.setTryResourceExpr(assignClientVariableWithCreateMethodExpr(clientVarExpr))
.setTryBody(bodyStatements)
.setIsSampleCode(true)
.build();
Expand Down Expand Up @@ -212,20 +214,20 @@ private static List<Expr> mapMethodArgumentsToVariableExprs(List<MethodArgument>
}

private static Expr createIteratorAllMethodExpr(
Method method, TypeNode clientType, List<MethodArgument> arguments) {
Method method, VariableExpr clientVarExpr, List<MethodArgument> arguments) {
// e.g echoClient.echo(name).iterateAll()
return MethodInvocationExpr.builder()
.setExprReferenceExpr(
MethodInvocationExpr.builder()
.setExprReferenceExpr(createVariableExpr(getClientName(clientType), clientType))
.setExprReferenceExpr(clientVarExpr)
.setMethodName(method.name())
.setArguments(
!arguments.isEmpty()
? mapMethodArgumentsToVariableExprs(arguments)
: Arrays.asList(createVariableExpr("request", method.inputType())))
.build())
.setMethodName("iterateAll")
.setReturnType(clientType)
.setReturnType(clientVarExpr.variable().type())
.build();
}

Expand Down
22 changes: 11 additions & 11 deletions test/integration/goldens/asset/AssetServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
* <pre>{@code
* AssetServiceSettings assetServiceSettings =
* AssetServiceSettings.newBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create("myCredentials"))
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings);
* }</pre>
Expand All @@ -87,7 +87,7 @@
*
* <pre>{@code
* AssetServiceSettings assetServiceSettings =
* AssetServiceSettings.newBuilder().setEndpoint("myEndpoint").build();
* AssetServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
* AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings);
* }</pre>
*/
Expand Down Expand Up @@ -170,7 +170,7 @@ public final OperationsClient getOperationsClient() {
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* // Note: Not Implement yet, placeholder for unary lro default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary lro default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -229,7 +229,7 @@ public final UnaryCallable<ExportAssetsRequest, Operation> exportAssetsCallable(
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -288,7 +288,7 @@ public final Feed createFeed(String parent) {
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -364,7 +364,7 @@ public final Feed getFeed(String name) {
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -416,7 +416,7 @@ public final ListFeedsResponse listFeeds(String parent) {
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -468,7 +468,7 @@ public final Feed updateFeed(Feed feed) {
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -546,7 +546,7 @@ public final Empty deleteFeed(String name) {
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -657,7 +657,7 @@ public final SearchAllResourcesPagedResponse searchAllResources(
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* // Note: Not Implement yet, placeholder for unary paged default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary paged default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -768,7 +768,7 @@ public final SearchAllIamPoliciesPagedResponse searchAllIamPolicies(String scope
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* // Note: Not Implement yet, placeholder for unary paged default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary paged default rpc method sample code.
* }
* }</pre>
*
Expand Down
34 changes: 17 additions & 17 deletions test/integration/goldens/logging/ConfigServiceV2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* <pre>{@code
* ConfigServiceV2Settings configServiceV2Settings =
* ConfigServiceV2Settings.newBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create("myCredentials"))
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* ConfigServiceV2Client configServiceV2Client =
* ConfigServiceV2Client.create(configServiceV2Settings);
Expand All @@ -86,7 +86,7 @@
*
* <pre>{@code
* ConfigServiceV2Settings configServiceV2Settings =
* ConfigServiceV2Settings.newBuilder().setEndpoint("myEndpoint").build();
* ConfigServiceV2Settings.newBuilder().setEndpoint(myEndpoint).build();
* ConfigServiceV2Client configServiceV2Client =
* ConfigServiceV2Client.create(configServiceV2Settings);
* }</pre>
Expand Down Expand Up @@ -316,7 +316,7 @@ public final ListBucketsPagedResponse listBuckets(String parent) {
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary paged default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary paged default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -356,7 +356,7 @@ public final UnaryCallable<ListBucketsRequest, ListBucketsResponse> listBucketsC
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -394,7 +394,7 @@ public final UnaryCallable<GetBucketRequest, LogBucket> getBucketCallable() {
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -574,7 +574,7 @@ public final ListSinksPagedResponse listSinks(String parent) {
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary paged default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary paged default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -668,7 +668,7 @@ public final LogSink getSink(String sinkName) {
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -867,7 +867,7 @@ public final LogSink createSink(String parent, LogSink sink) {
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -1074,7 +1074,7 @@ public final LogSink updateSink(String sinkName, LogSink sink, FieldMask updateM
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -1167,7 +1167,7 @@ public final Empty deleteSink(String sinkName) {
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -1339,7 +1339,7 @@ public final ListExclusionsPagedResponse listExclusions(String parent) {
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary paged default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary paged default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -1435,7 +1435,7 @@ public final LogExclusion getExclusion(String name) {
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -1622,7 +1622,7 @@ public final LogExclusion createExclusion(String parent, LogExclusion exclusion)
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -1736,7 +1736,7 @@ public final LogExclusion updateExclusion(
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -1820,7 +1820,7 @@ public final Empty deleteExclusion(String name) {
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -1855,7 +1855,7 @@ public final UnaryCallable<DeleteExclusionRequest, Empty> deleteExclusionCallabl
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -1901,7 +1901,7 @@ public final UnaryCallable<GetCmekSettingsRequest, CmekSettings> getCmekSettings
*
* <pre>{@code
* try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down
14 changes: 7 additions & 7 deletions test/integration/goldens/logging/LoggingServiceV2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
* <pre>{@code
* LoggingServiceV2Settings loggingServiceV2Settings =
* LoggingServiceV2Settings.newBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create("myCredentials"))
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* LoggingServiceV2Client loggingServiceV2Client =
* LoggingServiceV2Client.create(loggingServiceV2Settings);
Expand All @@ -88,7 +88,7 @@
*
* <pre>{@code
* LoggingServiceV2Settings loggingServiceV2Settings =
* LoggingServiceV2Settings.newBuilder().setEndpoint("myEndpoint").build();
* LoggingServiceV2Settings.newBuilder().setEndpoint(myEndpoint).build();
* LoggingServiceV2Client loggingServiceV2Client =
* LoggingServiceV2Client.create(loggingServiceV2Settings);
* }</pre>
Expand Down Expand Up @@ -216,7 +216,7 @@ public final Empty deleteLog(String logName) {
*
* <pre>{@code
* try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -400,7 +400,7 @@ public final WriteLogEntriesResponse writeLogEntries(
*
* <pre>{@code
* try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -484,7 +484,7 @@ public final ListLogEntriesPagedResponse listLogEntries(
*
* <pre>{@code
* try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary paged default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary paged default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -529,7 +529,7 @@ public final ListLogEntriesPagedResponse listLogEntries(ListLogEntriesRequest re
*
* <pre>{@code
* try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary paged default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary paged default rpc method sample code.
* }
* }</pre>
*
Expand Down Expand Up @@ -721,7 +721,7 @@ public final ListLogsPagedResponse listLogs(String parent) {
*
* <pre>{@code
* try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
* // Note: Not Implement yet, placeholder for unary paged default rpc method sample code.
* // Note: Not implemented yet, placeholder for unary paged default rpc method sample code.
* }
* }</pre>
*
Expand Down
Loading

0 comments on commit 51a0cbf

Please sign in to comment.