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

[Bug]: Simple case with wrong package name of used external class #5150

Open
salmonb opened this issue Apr 1, 2023 · 0 comments
Open

[Bug]: Simple case with wrong package name of used external class #5150

salmonb opened this issue Apr 1, 2023 · 0 comments
Labels

Comments

@salmonb
Copy link

salmonb commented Apr 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant