Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

@@ -401,8 +401,16 @@ String lookupName(ClassName className) {

// If the class is in the same package, we're done.
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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants