spoon
spoon copied to clipboard
[Bug]: Simple case with wrong package name of used external class
Describe the bug
When asking to parse 2 classes a.A & b.B and a.A is using an external class c.C through b.B (see simple code below), the parser reports that a.A is using b.C instead of c.C (C belongs to package c and not b).
Source code you are trying to analyze/transform
// First file A.java
package a;
import b.B;
public class A {
public static void callC(B b) {
b.getC().xxx();
}
}
// Second file B.java
package b;
import c.C; // external source not provided
public interface B {
C getC();
}
Source code for your Spoon processing
Launcher launcher = new Launcher();
launcher.addInputResource(inputSource);
CtModel model = launcher.buildModel();
for (CtElement ctClass : model.getElements(e -> e instanceof CtClass || e instanceof CtInterface)) {
CtType<?> ctType = (CtType<?>) ctClass;
System.out.println(ctType.getQualifiedName() + " is using:");
for (CtTypeReference<?> type : ctType.getUsedTypes(true)) {
System.out.println(" - " + type.getQualifiedName());
}
}
Actual output
a.A is using:
- b.C
- b.B
b.B is using:
- c.C
Expected output
a.A is using:
- c.C
- b.B
b.B is using:
- c.C
Spoon Version
10.3.0
JVM Version
11
What operating system are you using?
macOS 11.7.4 (BigSur) - IntelliJ IDEA 2023.1