From 13d96a53d4ae0a0665df8cef4d0eee3c34f93db0 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 18 Jul 2023 13:18:57 -0400 Subject: [PATCH] chore: resource name class composer cleanup (#1860) * chore: add resource name golden from collisions.proto * chore: improve deduplication logic * chore: finish test case * chore: unnecessary proto definitions * chore: format * chore: remove commented line in collisions.proto * chore: simplify deduplication logic * chore: revert changes in TypeStore.java * chore: improve javadoc of `createImplementsTypes` * chore: logic cleanup of `ResourceNameHelperClassComposer` --- .../ResourceNameHelperClassComposer.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java index b9dc386a9e..7f07658faf 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java @@ -131,7 +131,7 @@ public GapicClass generate(ResourceName resourceName, GapicContext context) { .setAnnotations(createClassAnnotations()) .setScope(ScopeNode.PUBLIC) .setName(className) - .setImplementsTypes(createImplementsTypes(className)) + .setImplementsTypes(Arrays.asList(createImplementsTypes(className))) .setStatements( createClassStatements( templateFinalVarExprs, @@ -165,22 +165,21 @@ private static List createClassAnnotations() { * * @param implementingClassName class that is implementing the resulting list */ - private static List createImplementsTypes(String implementingClassName) { + private static TypeNode createImplementsTypes(String implementingClassName) { // the original resource name reference has useFullName == false TypeNode originalResourceName = FIXED_TYPESTORE.get("ResourceName"); if (implementingClassName.equals(originalResourceName.reference().name())) { // we create a copy with useFullName == true - return Arrays.asList( - TypeNode.withReference( - ConcreteReference.builder() - .setUseFullName(true) - .setClazz(com.google.api.resourcenames.ResourceName.class) - .setGenerics(originalResourceName.reference().generics()) - .setIsStaticImport(originalResourceName.reference().isStaticImport()) - .setWildcardUpperBound(originalResourceName.reference().wildcardUpperBound()) - .build())); + return TypeNode.withReference( + ConcreteReference.builder() + .setUseFullName(true) + .setClazz(com.google.api.resourcenames.ResourceName.class) + .setGenerics(originalResourceName.reference().generics()) + .setIsStaticImport(originalResourceName.reference().isStaticImport()) + .setWildcardUpperBound(originalResourceName.reference().wildcardUpperBound()) + .build()); } - return Arrays.asList(originalResourceName); + return originalResourceName; } private static List createTemplateClassMembers(