Skip to content

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

Open
@ElvisLiaooo

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions