Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -48,6 +48,7 @@
public class ServiceStubClassComposer implements ClassComposer {
private static final ServiceStubClassComposer INSTANCE = new ServiceStubClassComposer();
private static final String DOT = ".";
private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse";

private ServiceStubClassComposer() {}

Expand Down Expand Up @@ -110,22 +111,30 @@ private static List<MethodDefinition> createCallableGetters(
if (method.hasLro()) {
javaMethods.add(createOperationCallableGetter(method, types));
}
if (method.isPaged()) {
javaMethods.add(createPagedCallableGetter(method, types));
}
javaMethods.add(createCallableGetter(method, types));
}
return javaMethods;
}

private static MethodDefinition createOperationCallableGetter(
Method method, Map<String, TypeNode> types) {
return createCallableGetterHelper(method, types, true);
return createCallableGetterHelper(method, types, true, false);
}

private static MethodDefinition createPagedCallableGetter(
Method method, Map<String, TypeNode> types) {
return createCallableGetterHelper(method, types, false, true);
}

private static MethodDefinition createCallableGetter(Method method, Map<String, TypeNode> types) {
return createCallableGetterHelper(method, types, false);
return createCallableGetterHelper(method, types, false, false);
}

private static MethodDefinition createCallableGetterHelper(
Method method, Map<String, TypeNode> types, boolean isLroCallable) {
Method method, Map<String, TypeNode> types, boolean isLroCallable, boolean isPaged) {
TypeNode returnType;
switch (method.stream()) {
case CLIENT:
Expand All @@ -146,12 +155,16 @@ private static MethodDefinition createCallableGetterHelper(
String methodName =
String.format(
"%s%sCallable",
JavaStyle.toLowerCamelCase(method.name()), (isLroCallable ? "Operation" : ""));
JavaStyle.toLowerCamelCase(method.name()),
(isLroCallable ? "Operation" : isPaged ? "Paged" : ""));
List<Reference> genericRefs = new ArrayList<>();
genericRefs.add(method.inputType().reference());
if (method.hasLro()) {
genericRefs.add(method.lro().responseType().reference());
genericRefs.add(method.lro().metadataType().reference());
} else if (isPaged) {
genericRefs.add(
types.get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())).reference());
} else {
genericRefs.add(method.outputType().reference());
}
Expand Down Expand Up @@ -237,6 +250,22 @@ private static Map<String, TypeNode> createTypes(
.setName("OperationsStub")
.setPakkage("com.google.longrunning.stub")
.build()));
// Pagination types.
types.putAll(
service.methods().stream()
.filter(m -> m.isPaged())
.collect(
Collectors.toMap(
m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name()),
m ->
TypeNode.withReference(
VaporReference.builder()
.setName(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name()))
.setPakkage(service.pakkage())
.setEnclosingClassName(getClientClassName(service.name()))
.setIsStaticImport(true)
.build()))));

return types;
}

Expand All @@ -249,4 +278,8 @@ private static List<Statement> createThrowUOEBody(
.setMessageExpr(String.format("Not implemented: %s()", methodName))
.build()));
}

private static String getClientClassName(String serviceName) {
return String.format("%sClient", serviceName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public void generateServiceClasses() {
// TODO(miraleung): Update this when a file-diffing test mechanism is in place.
private static final String EXPECTED_CLASS_STRING =
"package com.google.showcase.v1beta1.stub;\n"
+ "\n"
+ "import static com.google.showcase.v1beta1.EchoClient.PagedExpandPagedResponse;\n"
+ "\n"
+ "import com.google.api.gax.core.BackgroundResource;\n"
+ "import com.google.api.gax.rpc.BidiStreamingCallable;\n"
Expand Down Expand Up @@ -118,6 +120,12 @@ public void generateServiceClasses() {
+ " chatAgainCallable()\");\n"
+ " }\n"
+ "\n"
+ " public UnaryCallable<PagedExpandRequest, PagedExpandPagedResponse> pagedExpandPagedCallable()"
+ " {\n"
+ " throw new UnsupportedOperationException(\"Not implemented:"
+ " pagedExpandPagedCallable()\");\n"
+ " }\n"
+ "\n"
+ " public UnaryCallable<PagedExpandRequest, PagedExpandResponse> pagedExpandCallable()"
+ " {\n"
+ " throw new UnsupportedOperationException(\"Not implemented:"
Expand Down