Fix #860: Nested Type name clashes within same package#879
Fix #860: Nested Type name clashes within same package#879BigJIU wants to merge 1 commit intosquare:masterfrom
Conversation
| if (Objects.equals(packageName, className.packageName())) { | ||
| referencedNames.add(topLevelSimpleName); | ||
| return join(".", className.simpleNames()); | ||
| String conflictClassName = packageName+"."+className.simpleName;//From same package (Nest) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Thanks for the fix! but what do you need this line for? It is already checked that
packageNameequal toclassName.packageName(), sopackageName+"."+className.simpleNameis equivalent toclassName.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
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 becom.squareup.javapoet.Nestand theNestshould 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.