Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

Commit a66d56b

Browse files
authored
[ggj][codegen] fix: handle map/list args in ServiceClient (#331)
* 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
1 parent 7ff5375 commit a66d56b

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,8 @@ private static List<MethodDefinition> createMethodVariants(
487487
? types.get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name()))
488488
: method.outputType();
489489
String methodInputTypeName = methodInputType.reference().name();
490-
491-
Message inputMessage = messageTypes.get(methodInputTypeName);
492-
Preconditions.checkNotNull(
493-
inputMessage, String.format("Message %s not found", methodInputTypeName));
490+
Reference listRef = ConcreteReference.withClazz(List.class);
491+
Reference mapRef = ConcreteReference.withClazz(Map.class);
494492

495493
// Make the method signature order deterministic, which helps with unit testing and per-version
496494
// diffs.
@@ -543,7 +541,16 @@ private static List<MethodDefinition> createMethodVariants(
543541
for (MethodArgument argument : signature) {
544542
String argumentName = JavaStyle.toLowerCamelCase(argument.name());
545543
TypeNode argumentType = argument.type();
546-
String setterMethodName = String.format("set%s", JavaStyle.toUpperCamelCase(argumentName));
544+
String setterMethodVariantPattern = "set%s";
545+
if (TypeNode.isReferenceType(argumentType)) {
546+
if (listRef.isSupertypeOrEquals(argumentType.reference())) {
547+
setterMethodVariantPattern = "addAll%s";
548+
} else if (mapRef.isSupertypeOrEquals(argumentType.reference())) {
549+
setterMethodVariantPattern = "putAll%s";
550+
}
551+
}
552+
String setterMethodName =
553+
String.format(setterMethodVariantPattern, JavaStyle.toUpperCamelCase(argumentName));
547554

548555
Expr argVarExpr =
549556
VariableExpr.withVariable(

0 commit comments

Comments
 (0)