Skip to content

9160: Do not try to auto-import simple enum names in switches, that are 'in scope' due to enum switch target typing.#9200

Open
lahodaj wants to merge 1 commit intoapache:masterfrom
lahodaj:GITHUB-9160
Open

9160: Do not try to auto-import simple enum names in switches, that are 'in scope' due to enum switch target typing.#9200
lahodaj wants to merge 1 commit intoapache:masterfrom
lahodaj:GITHUB-9160

Conversation

@lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Feb 10, 2026

Consider code like:

package test;
import static test.E.A;
public class Test {
    private void test(E e) {
        switch (e) {
            case A:
            case B:
            case C:
                System.err.println(A);
                break;
        }
    }
}
enum E {
    A, B, C;
}

And copy&paste to another file. This should not propose to add imports for B and C (it should for A, as that's used in the System.err.println).

@lahodaj lahodaj added this to the NB30 milestone Feb 10, 2026
@lahodaj lahodaj added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Feb 10, 2026
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only eyeballed this, but logic makes sense to me. I have a minimal nitpick for the test: A method that does a clip board copy should not be named doCopyAndPaste. 😄

assertEquals(golden, actual[0]);
}

private FileObject doCopyAndPaste(String from, String sourceLevel) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private FileObject doCopyAndPaste(String from, String sourceLevel) throws Exception {
private FileObject doCopy(String from, String sourceLevel) throws Exception {

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

Labels

ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy-pasting a switch statement with enum constants from a switch case triggers unnecessary import dialog

2 participants