Skip to content

Commit

Permalink
[ggj][codegen] fix: generate param-less RPC Java methods for empty si…
Browse files Browse the repository at this point in the history
…gs (#575)

* fix: handle empty method_signature in parsing protos

* fix: add google/type:type_java_proto as default test dep

* fix: support singleton resource names in parsing and codegen

* fix: generate param-less RPC Java methods for empty sigs

* fix: merge master
  • Loading branch information
miraleung committed Nov 26, 2020
1 parent d3fea22 commit 00c6ad6
Show file tree
Hide file tree
Showing 11 changed files with 439 additions and 45 deletions.
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);
}
}
}

0 comments on commit 00c6ad6

Please sign in to comment.