INRIA / spoon

Spoon is a metaprogramming library to analyze and transform Java source code. :spoon: is made with :heart:, :beers: and :sparkles:. It parses source files to build a well-designed AST with powerful analysis and transformation API.
http://spoon.gforge.inria.fr/
Other
1.76k stars 352 forks source link

[Bug]: Spoon 9.1.0, auto import is not working properly with import static #6057

Open ElvisLiaooo opened 2 weeks ago

ElvisLiaooo commented 2 weeks ago

Describe the bug

Because my project is still using JDK8, I have to use older version 9.1.0 of Spoon. When setting auto import to true, the import static statement in the source file is missing from the spoon generated sources in some circumstances. I can reproduce the issue if I define a class with public static field and refer it in another class using static import.

Source code you are trying to analyze/transform

package com.elvis;
public class StaticClassModel {
    public static final String STATIC_FIELD = "static field";
}

package com.elvis;
import static com.elvis.StaticClassModel.*;
public class StaticTest {
    public void doSomeTest() {
        System.out.println(STATIC_FIELD);
    }
}

Source code for your Spoon processing

using spoon-maven-plugin

Actual output

package com.elvis;

public class StaticTest {
    public void doSomeTest() {
        System.out.println(STATIC_FIELD);
    }
}

Expected output

package com.elvis;
import static com.elvis.StaticClassModel.*;

public class StaticTest {
    public void doSomeTest() {
        System.out.println(STATIC_FIELD);
    }
}

Spoon Version

9.1.0

JVM Version

1.8

What operating system are you using?

MacOS 15.1