You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Confusion between simple access to class fields (or enum) and fully qualified name #5151
Having imported an external class C (source not provided) with import c.C;, then when parsing expressions like C.XXX, the parser should understand that C is referring to the class C, and not to a fully qualified class XXX in package C.
For example, the 2 following classes A and B should have the same result, but the parser is making that confusion with B.
Source code you are trying to analyze/transform
// First file A.javapackagea;
importc.C; // external source not providedpublicclassA {
publicstaticvoida() {
Cc = C.XXX; // C.XXX may be an enum, or a fieldSystem.out.println(c);
}
}
// Second file B.javapackageb;
importc.C;
publicclassB {
publicstaticvoidb() {
System.out.println(C.XXX);
}
}
Source code for your Spoon processing
Launcherlauncher = newLauncher();
launcher.addInputResource(inputSource);
CtModelmodel = launcher.buildModel();
// Find all the packages used in the codefor (CtElementctClass : model.getElements(e -> einstanceofCtClass || einstanceofCtInterface)) {
CtType<?> ctType = (CtType<?>) ctClass;
System.out.println(ctType.getQualifiedName() + " is using:");
for (CtTypeReference<?> type : ctType.getUsedTypes(true)) {
System.out.println(" - " + type.getQualifiedName() + " (package " + type.getPackage() + ")");
}
}
Activity
fix: Use a better heuristic for guessing type/field references in no …