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

Bug 545161

Summary: [12][extract method] Does not pass the variable used in switch expression to extracted method
Product: [Eclipse Project] JDT Reporter: Noopur Gupta <noopur_gupta>
Component: UIAssignee: Kalyan Prasad Tatavarthi <kalyan_prasad>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 4.11   
Target Milestone: BETA J12   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/138710
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=fe49b5fe962e9d503d5c27aed3845fe49b6fb6d8
Whiteboard:
Bug Depends on: 545193    
Bug Blocks: 545120    

Description Noopur Gupta CLA 2019-03-07 06:05:53 EST
String foo(Day day) {
		int x = 0;
		var today = switch(day){
			case SATURDAY, SUNDAY: break "Weekend day";
			case MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY: {
		   	 var kind = "Working day";
		    	break kind;
			}
			default: {
		    	var kind = day.name();
		   	 System.out.println(kind + x);
		   	 throw new IllegalArgumentException("Invalid day: " + kind);
			}
		  };

		return today;
	}

- Extract switch to a new method. The result is:
...
int x = 0;
var today = m();
...

private String m() {
...
}
Comment 1 Eclipse Genie CLA 2019-03-14 01:37:35 EDT
New Gerrit change created: https://git.eclipse.org/r/138710
Comment 2 Eclipse Genie CLA 2019-03-14 07:09:20 EDT
Gerrit change https://git.eclipse.org/r/138710 was merged to [BETA_JAVA_12].
Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=fe49b5fe962e9d503d5c27aed3845fe49b6fb6d8
Comment 3 Noopur Gupta CLA 2019-03-14 11:18:50 EDT
We need to add tests also after bug 545193 is resolved.