Skip to content

[ggj][codegen] fix: generate param-less RPC Java methods for empty sigs #575

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

Merged
merged 7 commits into from
Nov 26, 2020
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 @@ -424,6 +424,7 @@ private static List<MethodDefinition> createTestMethods(
service,
Collections.emptyList(),
0,
true,
classMemberVarExprs,
resourceNames,
messageTypes));
Expand All @@ -444,6 +445,7 @@ private static List<MethodDefinition> createTestMethods(
service,
method.methodSignatures().get(i),
i,
false,
classMemberVarExprs,
resourceNames,
messageTypes));
Expand All @@ -467,6 +469,7 @@ private static MethodDefinition createRpcTestMethod(
Service service,
List<MethodArgument> methodSignature,
int variantIndex,
boolean isRequestArg,
Map<String, VariableExpr> classMemberVarExprs,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes) {
Expand Down Expand Up @@ -584,7 +587,6 @@ private static MethodDefinition createRpcTestMethod(
methodStatements.add(EMPTY_LINE_STATEMENT);

// Construct the request or method arguments.
boolean isRequestArg = methodSignature.isEmpty();
VariableExpr requestVarExpr = null;
Message requestMessage = null;
List<VariableExpr> argExprs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.collect.Lists;
import com.google.protobuf.Descriptors.MethodDescriptor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -61,6 +62,7 @@ public static List<List<MethodArgument>> parseMethodSignatures(
// stringSigs: ["content,error", "content,error,info"].
for (String stringSig : stringSigs) {
if (Strings.isNullOrEmpty(stringSig)) {
signatures.add(Collections.emptyList());
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ public class EchoClient implements BackgroundResource {
return operationsClient;
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final EchoResponse echo() {
EchoRequest request = EchoRequest.newBuilder().build();
return echo(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* @param parent
Expand Down Expand Up @@ -280,6 +290,38 @@ public class EchoClient implements BackgroundResource {
return stub.pagedExpandCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final SimplePagedExpandPagedResponse simplePagedExpand() {
PagedExpandRequest request = PagedExpandRequest.newBuilder().build();
return simplePagedExpand(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final SimplePagedExpandPagedResponse simplePagedExpand(PagedExpandRequest request) {
return simplePagedExpandPagedCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/** Sample code: */
public final UnaryCallable<PagedExpandRequest, SimplePagedExpandPagedResponse>
simplePagedExpandPagedCallable() {
return stub.simplePagedExpandPagedCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/** Sample code: */
public final UnaryCallable<PagedExpandRequest, PagedExpandResponse> simplePagedExpandCallable() {
return stub.simplePagedExpandCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* @param ttl
Expand Down Expand Up @@ -445,4 +487,86 @@ public class EchoClient implements BackgroundResource {
return new PagedExpandFixedSizeCollection(pages, collectionSize);
}
}

public static class SimplePagedExpandPagedResponse
extends AbstractPagedListResponse<
PagedExpandRequest,
PagedExpandResponse,
EchoResponse,
SimplePagedExpandPage,
SimplePagedExpandFixedSizeCollection> {

public static ApiFuture<SimplePagedExpandPagedResponse> createAsync(
PageContext<PagedExpandRequest, PagedExpandResponse, EchoResponse> context,
ApiFuture<PagedExpandResponse> futureResponse) {
ApiFuture<SimplePagedExpandPage> futurePage =
SimplePagedExpandPage.createEmptyPage().createPageAsync(context, futureResponse);
return ApiFutures.transform(
futurePage,
new ApiFunction<SimplePagedExpandPage, SimplePagedExpandPagedResponse>() {
@Override
public SimplePagedExpandPagedResponse apply(SimplePagedExpandPage input) {
return new SimplePagedExpandPagedResponse(input);
}
},
MoreExecutors.directExecutor());
}

private SimplePagedExpandPagedResponse(SimplePagedExpandPage page) {
super(page, SimplePagedExpandFixedSizeCollection.createEmptyCollection());
}
}

public static class SimplePagedExpandPage
extends AbstractPage<
PagedExpandRequest, PagedExpandResponse, EchoResponse, SimplePagedExpandPage> {

private SimplePagedExpandPage(
PageContext<PagedExpandRequest, PagedExpandResponse, EchoResponse> context,
PagedExpandResponse response) {
super(context, response);
}

private static SimplePagedExpandPage createEmptyPage() {
return new SimplePagedExpandPage(null, null);
}

@Override
protected SimplePagedExpandPage createPage(
PageContext<PagedExpandRequest, PagedExpandResponse, EchoResponse> context,
PagedExpandResponse response) {
return new SimplePagedExpandPage(context, response);
}

@Override
public ApiFuture<SimplePagedExpandPage> createPageAsync(
PageContext<PagedExpandRequest, PagedExpandResponse, EchoResponse> context,
ApiFuture<PagedExpandResponse> futureResponse) {
return super.createPageAsync(context, futureResponse);
}
}

public static class SimplePagedExpandFixedSizeCollection
extends AbstractFixedSizeCollection<
PagedExpandRequest,
PagedExpandResponse,
EchoResponse,
SimplePagedExpandPage,
SimplePagedExpandFixedSizeCollection> {

private SimplePagedExpandFixedSizeCollection(
List<SimplePagedExpandPage> pages, int collectionSize) {
super(pages, collectionSize);
}

private static SimplePagedExpandFixedSizeCollection createEmptyCollection() {
return new SimplePagedExpandFixedSizeCollection(null, 0);
}

@Override
protected SimplePagedExpandFixedSizeCollection createCollection(
List<SimplePagedExpandPage> pages, int collectionSize) {
return new SimplePagedExpandFixedSizeCollection(pages, collectionSize);
}
}
}
Loading