Bug 545342 - Convert switch statement to switch expression
Summary: Convert switch statement to switch expression
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.11   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.18 M1   Edit
Assignee: Jeff Johnston CLA
QA Contact: Noopur Gupta CLA
URL:
Whiteboard:
Keywords: plan
Depends on: 567678
Blocks: 545120
  Show dependency tree
 
Reported: 2019-03-13 06:04 EDT by Noopur Gupta CLA
Modified: 2020-11-17 15:26 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Noopur Gupta CLA 2019-03-13 06:04:56 EDT
public static void foo(int num) {
		int res;
		switch (num) {
		case 100:
			res = 1;
			break;
		case 200:
			res = 2;
			break;
		case 300,3000:
			res = 3;
			break;
		case 400:
			res = 4;
			break;
		default:
			res = -1;
			break;
		}
		;
	}

	public static void foo1(int num) {
		int res= switch (num) {
		case 100-> 1;
		case 200-> 2;
		case 300,3000-> 3;
		case 400-> 4;
		default -> -1;
		};
	}

One example is given above i.e. convert from the code in #foo to #foo1.

The quick assist should also work for other possible scenarios.
Comment 1 Eclipse Genie CLA 2020-09-23 17:10:12 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/169800
Comment 3 Eclipse Genie CLA 2020-09-30 16:04:30 EDT
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/170129
Comment 5 Jeff Johnston CLA 2020-09-30 16:06:24 EDT
Released for 4.18M1
Comment 6 Noopur Gupta CLA 2020-10-01 10:51:48 EDT
(In reply to Jeff Johnston from comment #5)
> Released for 4.18M1

Thanks, Jeff.

@All, this feature has been released for M1 to get an early feedback. Please test and report any issues or possible improvements.
Comment 7 Eclipse Genie CLA 2020-10-07 06:08:39 EDT
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/170422
Comment 9 Sarika Sinha CLA 2020-10-07 06:18:56 EDT
2 scenarios when I get only 1 quick assist as "Convert to method" and "Convert to switch expression" is missing:
1. If I select till ";" which ends the switch statement.
2. If I select the code by dragging from down to up.
Comment 10 Noopur Gupta CLA 2020-10-07 06:23:45 EDT
For testing, please check if the scenarios are already described in the N&N, otheriwse open new bug reports: https://www.eclipse.org/eclipse/news/4.18/jdt.php#switch-expressions
Comment 11 Jeff Johnston CLA 2020-11-17 15:26:42 EST
Verified for 4.18M3 using I20201117-0600 build