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

Bug 352444

Summary: [extract local] 'Extract to local variable' refactoring produces incorrect code
Product: [Eclipse Project] JDT Reporter: Ankur Sharma <ankur_sharma>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, deepakazad
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Ankur Sharma CLA 2011-07-19 07:54:11 EDT
Snippet

		switch (string) {
		case "one":
			System.out.println("Accept");
			return true;
		case "two":
			System.out.println("Unsure");
			return true;
		default:
			System.out.println("Fail");
			return false;
		}


1. Select the string "two" in second case statement
2. Press Ctrl + 1 and invoke extract to local variable

The result is

		switch (string) {
		case "one":
			System.out.println("Accept");
			return true;
			String string2 = "two";
		case "two":
			System.out.println("Unsure");
			return true;
		default:
			System.out.println("Fail");
			return false;
		}


problem:
1. the statement 'String string2 = "two";' should be placed outside the scope of Switch 
2. The string "two" should have been replaced by string2 variable (even though that is wrong and would have compile error)
Comment 1 Deepak Azad CLA 2011-07-19 09:43:06 EDT
> 1. the statement 'String string2 = "two";' should be placed outside the scope
> of Switch 
Makes sense.

> 2. The string "two" should have been replaced by string2 variable (even though
> that is wrong and would have compile error)
This is bug 100871.

*** This bug has been marked as a duplicate of bug 100871 ***
Comment 2 Dani Megert CLA 2011-07-19 09:51:03 EDT
Note that the declaration was put at the right location in 3.3 and older.