Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352444 - [extract local] 'Extract to local variable' refactoring produces incorrect code
Summary: [extract local] 'Extract to local variable' refactoring produces incorrect code
Status: CLOSED DUPLICATE of bug 100871
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-19 07:54 EDT by Ankur Sharma CLA
Modified: 2011-07-19 09:51 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.