IDEA-203119 Unwrap switch statement: support rule-cases and multiple expression cases

This commit is contained in:
Tagir Valeev
2018-11-28 19:00:04 +07:00
parent c51a61c71d
commit 81c9810bde
11 changed files with 228 additions and 5 deletions
@@ -0,0 +1,25 @@
// "Unwrap 'switch' statement" "true"
class Main {
static void fff(int x) {
if (x == 5) {
switch (x) {
//1
//2
//3
//4
case 5:
if (Math.random() > 0.5) break;
System.out.println("five-ten-fifteen"); //5
System.out.println("six"); //6
System.out.println("seven"); //7
break;
//other
}
System.out.println("oops");
}
}
public static void main(String[] args) {
fff();
}
}
@@ -0,0 +1,24 @@
// "Unwrap 'switch' statement" "true"
class Main {
static void fff(int x) {
if (x == 5) {
int i = 5;
//1
//2
//3
//4
//6
//7
//other
{
if (Math.random() > 0.5) return;
int i = 6;
System.out.println("five-ten-fifteen"); //5
}
}
}
public static void main(String[] args) {
fff();
}
}
@@ -0,0 +1,19 @@
// "Unwrap 'switch' statement" "true"
class Main {
static void fff(int x) {
if (x == 5) {
//1
//2
//3
//4
System.out.println("five-ten-fifteen"); //5
//6
//7
//other
}
}
public static void main(String[] args) {
fff();
}
}
@@ -0,0 +1,20 @@
// "Unwrap 'switch' statement" "true"
class Main {
static void fff(int x) {
if (x == 5) {
//1
//2
//3
//4
//6
//7
//other
if (Math.random() > 0.5) return;
System.out.println("five-ten-fifteen"); //5
}
}
public static void main(String[] args) {
fff();
}
}
@@ -0,0 +1,25 @@
// "Unwrap 'switch' statement" "true"
class Main {
static void fff(int x) {
if (x == 5) {
switch (x) {
case 1: System.out.println("one"); //1
case 2: System.out.println("two"); //2
case 3: System.out.println("three"); //3
case 4: System.out.println("four"); //4
case 0:case <caret>5:case 10:
if (Math.random() > 0.5) break;
System.out.println("five-ten-fifteen"); //5
case 6: System.out.println("six"); //6
case 7: System.out.println("seven"); //7
break;
default: System.out.println("and more"); //other
}
System.out.println("oops");
}
}
public static void main(String[] args) {
fff();
}
}
@@ -0,0 +1,26 @@
// "Unwrap 'switch' statement" "true"
class Main {
static void fff(int x) {
if (x == 5) {
int i = 5;
switch (x) {
case 1 -> System.out.println("one"); //1
case 2 -> System.out.println("two"); //2
case 3 -> System.out.println("three"); //3
case 4 -> System.out.println("four"); //4
case 0, <caret>5, 10 -> {
if (Math.random() > 0.5) break;
int i = 6;
System.out.println("five-ten-fifteen"); //5
}
case 6 -> System.out.println("six"); //6
case 7 -> System.out.println("seven"); //7
default -> System.out.println("and more"); //other
}
}
}
public static void main(String[] args) {
fff();
}
}
@@ -0,0 +1,21 @@
// "Unwrap 'switch' statement" "true"
class Main {
static void fff(int x) {
if (x == 5) {
switch (x) {
case 1 -> System.out.println("one"); //1
case 2 -> System.out.println("two"); //2
case 3 -> System.out.println("three"); //3
case 4 -> System.out.println("four"); //4
case 0, <caret>5, 10 -> System.out.println("five-ten-fifteen"); //5
case 6 -> System.out.println("six"); //6
case 7 -> System.out.println("seven"); //7
default -> System.out.println("and more"); //other
}
}
}
public static void main(String[] args) {
fff();
}
}
@@ -0,0 +1,24 @@
// "Unwrap 'switch' statement" "true"
class Main {
static void fff(int x) {
if (x == 5) {
switch (x) {
case 1 -> System.out.println("one"); //1
case 2 -> System.out.println("two"); //2
case 3 -> System.out.println("three"); //3
case 4 -> System.out.println("four"); //4
case 0, <caret>5, 10 -> {
if (Math.random() > 0.5) break;
System.out.println("five-ten-fifteen"); //5
}
case 6 -> System.out.println("six"); //6
case 7 -> System.out.println("seven"); //7
default -> System.out.println("and more"); //other
}
}
}
public static void main(String[] args) {
fff();
}
}