Bug 493214

Summary: [quick fix] Add option to static import enum literal where this is "obvious"
Product: [Eclipse Project] JDT Reporter: Lukas Eder <lukas.eder>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3    
Version: 4.6   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Lukas Eder CLA 2016-05-09 04:52:57 EDT
I have the following code:

------------------------------------------------
package test;

public @interface Test {

    E e() default X;

    enum E {
        X, Y, Z
    }
}
------------------------------------------------

In the above context, "default X" can mean only one thing: "default E.X". Unfortunately, quick fix only offers two options "create field X" and "create constant X", both of which don't even produce compilable code. Instead, the following two options would be very useful:

1. Static import E.X
2. Qualify X to be E.X

The respective output of the two refactorings would be:


1. Static import E.X
------------------------------------------------
package test;

import static test.Test.E.X;

public @interface Test {

    E e() default X;

    enum E {
        X, Y, Z
    }
}
------------------------------------------------

2. Qualify X to be E.X
------------------------------------------------
package test;

public @interface Test {

    E e() default E.X;

    enum E {
        X, Y, Z
    }
}
------------------------------------------------