Skip to content

Commit

Permalink
Refactor signatures, add todos, and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
summer-ji-eng committed Nov 17, 2020
1 parent b1f948f commit 04bc59b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ static List<CommentStatement> createClassHeaderComments(
clientName, clientType, settingsName, settingsType));
classHeaderJavadocBuilder.addParagraph(SERVICE_DESCRIPTION_ENDPOINT_SUMMARY_STRING);
classHeaderJavadocBuilder.addSampleCode(
ServiceClientSampleCodeComposer.composeClassHeaderEndpointSampleCode(service, types));
ServiceClientSampleCodeComposer.composeClassHeaderEndpointSampleCode(
clientName, clientType, settingsName, settingsType));

return Arrays.asList(
CommentComposer.AUTO_GENERATED_CLASS_COMMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.stream.Collectors;

public class ServiceClientSampleCodeComposer {
//TODO(summerji): Add unit tests for ServiceClientSampleCodeComposer.
// TODO(summerji): Add unit tests for ServiceClientSampleCodeComposer.

public static String composeClassHeaderCredentialsSampleCode(
String clientName, TypeNode clientType, String settingsName, TypeNode settingsType) {
Expand Down Expand Up @@ -92,13 +92,13 @@ public static String composeClassHeaderCredentialsSampleCode(
}

public static String composeClassHeaderEndpointSampleCode(
Service service, Map<String, TypeNode> types) {
String settingsVarName = JavaStyle.toLowerCamelCase(getSettingsName(service.name()));
TypeNode settingsVarType = types.get(getSettingsName(service.name()));
VariableExpr settingsVarExpr = createVariableExpr(settingsVarName, settingsVarType);
String clientName, TypeNode clientType, String settingsName, TypeNode settingsType) {
// Initialize client settings with builder() method.
// e.g. EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint("myEndpoint").build();
VariableExpr settingsVarExpr = createVariableExpr(settingsName, settingsType);
MethodInvocationExpr newBuilderMethodExpr =
MethodInvocationExpr.builder()
.setStaticReferenceType(settingsVarType)
.setStaticReferenceType(settingsType)
.setMethodName("newBuilder")
.build();
MethodInvocationExpr credentialsMethodExpr =
Expand All @@ -110,7 +110,7 @@ public static String composeClassHeaderEndpointSampleCode(
MethodInvocationExpr buildMethodExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(credentialsMethodExpr)
.setReturnType(settingsVarType)
.setReturnType(settingsType)
.setMethodName("build")
.build();

Expand All @@ -120,8 +120,8 @@ public static String composeClassHeaderEndpointSampleCode(
.setValueExpr(buildMethodExpr)
.build();

String clientName = JavaStyle.toLowerCamelCase(getClientClassName(service.name()));
TypeNode clientType = types.get(getClientClassName(service.name()));
// Initialize client with create() method.
// e.g. EchoClient echoClient = EchoClient.create(echoSettings);
VariableExpr clientVarExpr = createVariableExpr(clientName, clientType);
MethodInvocationExpr createMethodExpr =
MethodInvocationExpr.builder()
Expand Down

0 comments on commit 04bc59b

Please sign in to comment.