From 31d9be62f318501fec4df2a2608012dc8cf8c36e Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Sat, 24 Oct 2020 16:28:51 -0700 Subject: [PATCH] [ggj][resname] fix: Fix resname helper method names for of* and format* (#408) * fix: refactor requestBuilder into separate method in ServiceClientClassComposer * feat: add varargs to AnonClass and ref setter methods * feat: add HTTP annotation parsing/validation * feat: Generate RequestParamsExtractor in GrpcServiceStub * feat: add GrpcPublisherStub test to exercise HTTP subfields * fix: add ByteString to DefaultValueComposer * fix: Use repeated field name for paged RPC unit tests * fix: refactor exception field, use paged repeated field name, add pubsub client test * fix: ensure all testgen methods throw Exceptions * fix: Fix resname helper method names for of* and format* --- .../ResourceNameHelperClassComposer.java | 8 ++++++-- .../gapic/composer/goldens/FoobarName.golden | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposer.java index 5594ffb16a..3fa6924b2e 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposer.java @@ -525,7 +525,8 @@ private static List createOfOrFormatMethodHelper( .setReturnType(returnType) .setName( String.format( - methodNameFormat, i == 0 ? "" : getBuilderTypeName(tokenHierarchies, i))) + methodNameFormat, + i == 0 ? "" : concatToUpperCamelCaseName(tokenHierarchies.get(i)) + "Name")) .setArguments(methodArgs) .setReturnExpr(returnExpr) .build()); @@ -537,7 +538,10 @@ private static List createOfOrFormatMethodHelper( .setIsStatic(true) .setAnnotations(annotations) .setReturnType(returnType) - .setName(String.format(methodNameFormat, getBuilderTypeName(tokens))) + .setName( + String.format( + methodNameFormat, + concatToUpperCamelCaseName(tokenHierarchies.get(i)) + "Name")) .setArguments(methodArgs) .setReturnExpr(returnExpr) .build()); diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/FoobarName.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/FoobarName.golden index 565f997703..3760e222d6 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/FoobarName.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/FoobarName.golden @@ -113,12 +113,12 @@ public class FoobarName implements ResourceName { } @BetaApi("The static create methods are not stable yet and may be changed in the future.") - public static FoobarName ofProjectFoobarBuilder(String project, String foobar) { + public static FoobarName ofProjectFoobarName(String project, String foobar) { return newBuilder().setProject(project).setFoobar(foobar).build(); } @BetaApi("The static create methods are not stable yet and may be changed in the future.") - public static FoobarName ofProjectVariantFoobarBuilder( + public static FoobarName ofProjectVariantFoobarName( String project, String variant, String foobar) { return newProjectVariantFoobarBuilder() .setProject(project) @@ -128,12 +128,12 @@ public class FoobarName implements ResourceName { } @BetaApi("The static create methods are not stable yet and may be changed in the future.") - public static FoobarName ofFoobarBuilder(String foobar) { + public static FoobarName ofFoobarName(String foobar) { return newFoobarBuilder().setFoobar(foobar).build(); } @BetaApi("The static create methods are not stable yet and may be changed in the future.") - public static FoobarName ofBarFooFoobarBuilder(String barFoo, String foobar) { + public static FoobarName ofBarFooFoobarName(String barFoo, String foobar) { return newBarFooFoobarBuilder().setBarFoo(barFoo).setFoobar(foobar).build(); } @@ -142,12 +142,12 @@ public class FoobarName implements ResourceName { } @BetaApi("The static format methods are not stable yet and may be changed in the future.") - public static String formatProjectFoobarBuilder(String project, String foobar) { + public static String formatProjectFoobarName(String project, String foobar) { return newBuilder().setProject(project).setFoobar(foobar).build().toString(); } @BetaApi("The static format methods are not stable yet and may be changed in the future.") - public static String formatProjectVariantFoobarBuilder( + public static String formatProjectVariantFoobarName( String project, String variant, String foobar) { return newProjectVariantFoobarBuilder() .setProject(project) @@ -158,12 +158,12 @@ public class FoobarName implements ResourceName { } @BetaApi("The static format methods are not stable yet and may be changed in the future.") - public static String formatFoobarBuilder(String foobar) { + public static String formatFoobarName(String foobar) { return newFoobarBuilder().setFoobar(foobar).build().toString(); } @BetaApi("The static format methods are not stable yet and may be changed in the future.") - public static String formatBarFooFoobarBuilder(String barFoo, String foobar) { + public static String formatBarFooFoobarName(String barFoo, String foobar) { return newBarFooFoobarBuilder().setBarFoo(barFoo).setFoobar(foobar).build().toString(); }