Skip to content

Commit

Permalink
chore: resource name class composer cleanup (#1860)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
diegomarquezp authored Jul 18, 2023
1 parent 08eca7d commit 13d96a5
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -165,22 +165,21 @@ private static List<AnnotationNode> createClassAnnotations() {
*
* @param implementingClassName class that is implementing the resulting list
*/
private static List<TypeNode> 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<VariableExpr> createTemplateClassMembers(
Expand Down

0 comments on commit 13d96a5

Please sign in to comment.