Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

Fix #860: Nested Type name clashes within same package#879

Open
BigJIU wants to merge 1 commit intosquare:masterfrom
BigJIU:BigJIU-nested-interface
Open

Fix #860: Nested Type name clashes within same package#879
BigJIU wants to merge 1 commit intosquare:masterfrom
BigJIU:BigJIU-nested-interface

Conversation

@BigJIU
Copy link

@BigJIU BigJIU commented Apr 21, 2022

As mentioned in #860 , when we are using a class with name both appearing in the inner declaration of current super class, and a individual class in current package, the later one's name would be the simplest form (e.g. Nest). However, it should be com.squareup.javapoet.Nest and the Nest should be the name of inner class.

Therefore, an judgement is added in the trim step in lookupname. With that, the name of external class in same package would not be trim any longer and will be write as its full name.

By the way, in order to test this situation, two other class is added in test. They don't look good, but that's the only way I know to get the bug's situation.

if (Objects.equals(packageName, className.packageName())) {
referencedNames.add(topLevelSimpleName);
return join(".", className.simpleNames());
String conflictClassName = packageName+"."+className.simpleName;//From same package (Nest)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! but what do you need this line for? It is already checked that packageName equal to className.packageName(), so packageName+"."+className.simpleName is equivalent to className.packageName() +"."+className.simpleName, right? Then you don't need the comparison to canonicalName below, because it is always true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! but what do you need this line for? It is already checked that packageName equal to className.packageName(), so packageName+"."+className.simpleName is equivalent to className.packageName() +"."+className.simpleName, right? Then you don't need the comparison to canonicalName below, because it is always true

Well, actually the conflictClassName is not always equal to the className.canonicalName, because of the existence of super class. The ignorance of trim only occur when the class is alwaysQualify and canonicalName equals, that is ,the class share a same name with a subclass but canonical name doesn't act like that. For more detail about the issue described situation, you can go to the avoidClashesWithNestedClasses_SamePackageTest in JavaFileTest

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants