Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 377287

Summary: [extract method] Refactor > Extract Constant does not extract case literal as a constant
Product: [Eclipse Project] JDT Reporter: Lukas Eder <lukas.eder>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: minor    
Priority: P3 CC: deepakazad, lukas.eder
Version: 3.7.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Lukas Eder CLA 2012-04-20 09:52:42 EDT
Build Identifier: Build Identifier: Version: Indigo Release Build id: 20110615-0604

I cannot extract case literals from a switch statement as constants (or variables)

Reproducible: Always

Steps to Reproduce:
1. Create this class:

------------------------------------
public class Test {
    public void x(int i) {
        switch (i) {
            case 0:
            case 1:
        }
    }
}
------------------------------------

2. Select 0 or 1, the case literals
3. Choose Refactor > Extract Constant from the context menu
4. Choose any options and click OK
5. A constant is created, but the original is not replaced, resulting in:

------------------------------------
public class Test {
    private static final int _1 = 1;

    public void x(int i) {
        switch (i) {
            case 0:
            case 1: // The literal is still here
        }
    }
}
------------------------------------
Comment 1 Deepak Azad CLA 2012-04-20 09:59:02 EDT
Please try with the latest 3.8 or 4.2 build.

*** This bug has been marked as a duplicate of bug 211529 ***