Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[samplecode][bug]fix credentials and endpoint sample code variable #530

Merged
merged 2 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import com.google.api.generator.engine.ast.ExprStatement;
import com.google.api.generator.engine.ast.MethodInvocationExpr;
import com.google.api.generator.engine.ast.Statement;
import com.google.api.generator.engine.ast.StringObjectValue;
import com.google.api.generator.engine.ast.TypeNode;
import com.google.api.generator.engine.ast.ValueExpr;
import com.google.api.generator.engine.ast.VaporReference;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.engine.writer.JavaWriterVisitor;
Expand All @@ -44,6 +43,12 @@ public static String composeClassHeaderCredentialsSampleCode(
// EchoSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create("myCredentials")).build();
String settingsName = JavaStyle.toLowerCamelCase(settingsType.reference().name());
String clientName = JavaStyle.toLowerCamelCase(clientType.reference().name());
TypeNode myCredentialsType =
TypeNode.withReference(
VaporReference.builder()
.setName("myCredentials")
.setPakkage(clientType.reference().pakkage())
.build());
VariableExpr settingsVarExpr = createVariableExpr(settingsName, settingsType);
MethodInvocationExpr newBuilderMethodExpr =
MethodInvocationExpr.builder()
Expand All @@ -55,7 +60,7 @@ public static String composeClassHeaderCredentialsSampleCode(
MethodInvocationExpr credentialArgExpr =
MethodInvocationExpr.builder()
.setStaticReferenceType(fixedCredentialProvideType)
.setArguments(ValueExpr.withValue(StringObjectValue.withValue("myCredentials")))
.setArguments(createVariableExpr("myCredentials", myCredentialsType))
.setMethodName("create")
.build();
MethodInvocationExpr credentialsMethodExpr =
Expand Down Expand Up @@ -103,6 +108,12 @@ public static String composeClassHeaderEndpointSampleCode(
// e.g. EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint("myEndpoint").build();
String settingsName = JavaStyle.toLowerCamelCase(settingsType.reference().name());
String clientName = JavaStyle.toLowerCamelCase(clientType.reference().name());
TypeNode myEndpointType =
TypeNode.withReference(
VaporReference.builder()
.setName("myEndpoint")
.setPakkage(clientType.reference().pakkage())
.build());
VariableExpr settingsVarExpr = createVariableExpr(settingsName, settingsType);
MethodInvocationExpr newBuilderMethodExpr =
MethodInvocationExpr.builder()
Expand All @@ -112,7 +123,7 @@ public static String composeClassHeaderEndpointSampleCode(
MethodInvocationExpr credentialsMethodExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(newBuilderMethodExpr)
.setArguments(ValueExpr.withValue(StringObjectValue.withValue("myEndpoint")))
.setArguments(createVariableExpr("myEndpoint", myEndpointType))
.setMethodName("setEndpoint")
.build();
MethodInvocationExpr buildMethodExpr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ import javax.annotation.Generated;
* <pre>{@code
* EchoSettings echoSettings =
* EchoSettings.newBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create("myCredentials"))
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* EchoClient echoClient = EchoClient.create(echoSettings);
* }</pre>
*
* <p>To customize the endpoint:
*
* <pre>{@code
* EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint("myEndpoint").build();
* EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint(myEndpoint).build();
* EchoClient echoClient = EchoClient.create(echoSettings);
* }</pre>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import javax.annotation.Generated;
* <pre>{@code
* IdentitySettings identitySettings =
* IdentitySettings.newBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create("myCredentials"))
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* IdentityClient identityClient = IdentityClient.create(identitySettings);
* }</pre>
Expand All @@ -65,7 +65,7 @@ import javax.annotation.Generated;
*
* <pre>{@code
* IdentitySettings identitySettings =
* IdentitySettings.newBuilder().setEndpoint("myEndpoint").build();
* IdentitySettings.newBuilder().setEndpoint(myEndpoint).build();
* IdentityClient identityClient = IdentityClient.create(identitySettings);
* }</pre>
*/
Expand Down
4 changes: 2 additions & 2 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
4 changes: 2 additions & 2 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
4 changes: 2 additions & 2 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
4 changes: 2 additions & 2 deletions test/integration/goldens/logging/MetricsServiceV2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
* <pre>{@code
* MetricsServiceV2Settings metricsServiceV2Settings =
* MetricsServiceV2Settings.newBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create("myCredentials"))
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* MetricsServiceV2Client metricsServiceV2Client =
* MetricsServiceV2Client.create(metricsServiceV2Settings);
Expand All @@ -85,7 +85,7 @@
*
* <pre>{@code
* MetricsServiceV2Settings metricsServiceV2Settings =
* MetricsServiceV2Settings.newBuilder().setEndpoint("myEndpoint").build();
* MetricsServiceV2Settings.newBuilder().setEndpoint(myEndpoint).build();
* MetricsServiceV2Client metricsServiceV2Client =
* MetricsServiceV2Client.create(metricsServiceV2Settings);
* }</pre>
Expand Down
4 changes: 2 additions & 2 deletions test/integration/goldens/redis/CloudRedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
* <pre>{@code
* CloudRedisSettings cloudRedisSettings =
* CloudRedisSettings.newBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create("myCredentials"))
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings);
* }</pre>
Expand All @@ -107,7 +107,7 @@
*
* <pre>{@code
* CloudRedisSettings cloudRedisSettings =
* CloudRedisSettings.newBuilder().setEndpoint("myEndpoint").build();
* CloudRedisSettings.newBuilder().setEndpoint(myEndpoint).build();
* CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings);
* }</pre>
*/
Expand Down