Skip to content

Commit

Permalink
[ggj][codegen] fix: handle map/list args in ServiceClient (#331)
Browse files Browse the repository at this point in the history
* feat: add protobuf comment parser util

* fix: add basic proto build rules

* feat: add header comments to ServiceClient

* fix: build protoc at test time

* fix!: wrap protobuf location and process comments

* feat: add comment parsing to methods and fields

* fix: test

* feat: add protobuf comments to ServiceClient

* fix: solidify codegen method order with TypeNode/MethodArg and Comparable

* fix: clean up tests

* fix: ServiceClient member variables and method calls

* fix: ServiceStubSettings builder type

* fix: ServiceSettings Builder construction

* fix: ServiceStub callable types

* feat: java_gapic_library rule impl

* fix: remove debugging comments

* feat: add gradle assembly Bazel rules

* feat: add java_gapic_test Bazel rule

* fix: use Java packages for resname codegen

* fix: build resnames separately and extract into proto/ dir

* fix: remove debug printf

* feat: add ServiceClient.MethodPagedResponse inner class

* feat: add ServiceClient.MethodPage inner class

* feat: add ServiceClient.MethodFixedSizeCollection innser class

* fix: clean up resname codegen, lower_snake varnames

* fix: init remaining resname tokenVars to null

* fix: ServiceStubSettings paged descriptor rep. field getter name

* fix: handle map/list args in ServiceClient
  • Loading branch information
miraleung authored Sep 19, 2020
1 parent 7ff5375 commit a66d56b
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,8 @@ private static List<MethodDefinition> createMethodVariants(
? types.get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name()))
: method.outputType();
String methodInputTypeName = methodInputType.reference().name();

Message inputMessage = messageTypes.get(methodInputTypeName);
Preconditions.checkNotNull(
inputMessage, String.format("Message %s not found", methodInputTypeName));
Reference listRef = ConcreteReference.withClazz(List.class);
Reference mapRef = ConcreteReference.withClazz(Map.class);

// Make the method signature order deterministic, which helps with unit testing and per-version
// diffs.
Expand Down Expand Up @@ -543,7 +541,16 @@ private static List<MethodDefinition> createMethodVariants(
for (MethodArgument argument : signature) {
String argumentName = JavaStyle.toLowerCamelCase(argument.name());
TypeNode argumentType = argument.type();
String setterMethodName = String.format("set%s", JavaStyle.toUpperCamelCase(argumentName));
String setterMethodVariantPattern = "set%s";
if (TypeNode.isReferenceType(argumentType)) {
if (listRef.isSupertypeOrEquals(argumentType.reference())) {
setterMethodVariantPattern = "addAll%s";
} else if (mapRef.isSupertypeOrEquals(argumentType.reference())) {
setterMethodVariantPattern = "putAll%s";
}
}
String setterMethodName =
String.format(setterMethodVariantPattern, JavaStyle.toUpperCamelCase(argumentName));

Expr argVarExpr =
VariableExpr.withVariable(
Expand Down

0 comments on commit a66d56b

Please sign in to comment.