Skip to content

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

@nmatt

Description

@nmatt

Apache NetBeans version

Apache NetBeans 28

What happened

When used as case labels in switch statements, enum constants don't need to be imported. However, copy-pasting such a switch statements has NetBeans unnecessarily trigger the "Import Classes" dialog, and creating unnecessary (and possibly conflicting) imports for the copied enum constants when the dialog is acknoledged with "OK".

Language / Project Type / NetBeans Component

Java, Editor, Refactoring

How to reproduce

Example

        switch (Thread.currentThread().getState())
        {
            case NEW: System.out.println("new"); break;
            case BLOCKED: System.out.println("blocked"); break;
            // etc.
        }

Copy the switch statement and paste it into the same or a differen Java source file.
=> The "Import Classes" dialog appears, unnecessarily wanting to add imports for the enum constants.

The same happens for arrow-style (->) case statements.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows

JDK

JDK 21

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

NetBeans should IMO recognize when an enum constant occurs within a case construct in the copy-pasted code, and for such occurrence not regard the constants as being in need of imports.

Are you willing to submit a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugBug report or fixneeds:triageRequires attention from one of the committers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions