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]: File is exists,but show unknown source position #5208

Closed
honghao12 opened this issue May 12, 2023 · 1 comment · Fixed by #5248
Closed

[Bug]: File is exists,but show unknown source position #5208

honghao12 opened this issue May 12, 2023 · 1 comment · Fixed by #5248
Labels

Comments

@honghao12
Copy link

honghao12 commented May 12, 2023

Describe the bug

1.In my code,the class ClassT1 is exists,
image
ClassT1.java

package p20;
public abstract class ClassT1 {
    ClassT3 classT3;

    public ClassT1(){
        this.classT3 = new ClassT3(this);
    }

    void fun2(ClassT3 classT3){
    }
}

ClassT2.java

package p20;
import p8.GlobalExecutor;

public class ClassT2 extends ClassT1 {
    public void fun(){
        GlobalExecutor.executeByCommon(() -> {
            fun2(classT3);
        });
    }
}

ClassT3.java

package p20;

public class ClassT3 {
    final ClassT1 classT1;

    public ClassT3(ClassT1 classT1) {
        this.classT1 = classT1;
    }
}

2.When i use the method getAllTypes to get the ctType,the ClassT1 ctType show unknown source position

    Launcher launcher = new Launcher();
    launcher.getEnvironment().setComplianceLevel(11);
    launcher.getEnvironment().setAutoImports(true);
    launcher.getEnvironment().setIgnoreDuplicateDeclarations(true);
    launcher.addInputResource("D:/javademo4/src/main/java/p20");
    CtModel model = launcher.buildModel();
    Collection<CtType<?>> allTypes = model.getAllTypes();
    for (CtType<?> ctType : allTypes) {
            if(!ctType.getPosition().isValidPosition()){
                log.warn("The ctType[{}] isn`t valid position.", ctType.getPath());
                continue;
            }
    }

image

Source code you are trying to analyze/transform

Launcher launcher = new Launcher();
    launcher.getEnvironment().setComplianceLevel(11);
    launcher.getEnvironment().setAutoImports(true);
    launcher.getEnvironment().setIgnoreDuplicateDeclarations(true);
    launcher.addInputResource("D:/javademo4/src/main/java/p20");
    CtModel model = launcher.buildModel();
    Collection<CtType<?>> allTypes = model.getAllTypes();
    for (CtType<?> ctType : allTypes) {
            if(!ctType.getPosition().isValidPosition()){
                log.warn("The ctType[{}] isn`t valid position.", ctType.getPath());
                continue;
            }
    }

Source code for your Spoon processing

ClassT1.java

package p20;
public abstract class ClassT1 {
    ClassT3 classT3;

    public ClassT1(){
        this.classT3 = new ClassT3(this);
    }

    void fun2(ClassT3 classT3){
    }
}

ClassT2.java

package p20;
import p8.GlobalExecutor;

public class ClassT2 extends ClassT1 {
    public void fun(){
        GlobalExecutor.executeByCommon(() -> {
            fun2(classT3);
        });
    }
}

ClassT3.java

package p20;

public class ClassT3 {
    final ClassT1 classT1;

    public ClassT3(ClassT1 classT1) {
        this.classT1 = classT1;
    }
}

Actual output

unknown source position

Expected output

exists source position

Spoon Version

 <dependency>
        <groupId>fr.inria.gforge.spoon</groupId>
        <artifactId>spoon-core</artifactId>
        <!-- See rendered release value at http://SpoonTest.gforge.inria.fr/ -->
        <version>10.3.0</version>
    </dependency>

JVM Version

11

What operating system are you using?

windows

@honghao12 honghao12 added the bug label May 12, 2023
@honghao12
Copy link
Author

If the GlobalExecutor class existed in my parse directory, this problem would not occur

package p20;

@SuppressWarnings("all")
public class GlobalExecutor {
    public static void executeByCommon(Runnable runnable) {
        return;
    }
}

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

Successfully merging a pull request may close this issue.

1 participant