ConvertSwitchToIfIntention: support Java 12 switch statements (no expressions)

This commit is contained in:
Tagir Valeev
2018-12-07 11:53:39 +07:00
parent 985d882482
commit bb990f4f13
11 changed files with 172 additions and 47 deletions

View File

@@ -0,0 +1,12 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void foo(int x) {
if (x == 0 || x == 1) {
System.out.println("ready");
System.out.println("steady");
} else if (x == 2 || x == 3) {
System.out.println("steady");
}
System.out.println("go");
}
}

View File

@@ -0,0 +1,16 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void foo(int x) {
//1
/*2*/
/*3*/
/*4*/
/*6*/
/*7*/
if (x == 0) {
System.out.println("zero");/*5*/
} else {
System.out.println("non-zero");/*8*/
}
}
}

View File

@@ -0,0 +1,10 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void foo(int x) {
if (x == 0) {
System.out.println(x);
} else if (x == 1) {
System.out.println("one");
}
}
}

View File

@@ -0,0 +1,13 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void foo(int x) {
if (x == 0 || x == 1) {
throw new IllegalArgumentException();
} else if (x == 2 || x == 3) {
if (Math.random() > 0.5) return;
System.out.println("two or three");
} else if (x == 4) {
System.out.println("four");
}
}
}

View File

@@ -0,0 +1,10 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void foo(int x) {
switch<caret> (x) {
case 0,1: System.out.println("ready");
case 2,3: System.out.println("steady");
default: System.out.println("go");
}
}
}

View File

@@ -0,0 +1,10 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void foo(int x) {
switch<caret> (x) {
//1
case /*2*/0/*3*/ -> /*4*/System.out.println("zero");/*5*/
default /*6*/->/*7*/ System.out.println("non-zero");/*8*/
}
}
}

View File

@@ -0,0 +1,9 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void foo(int x) {
switch<caret> (x) {
case 0 -> System.out.println(x);
case 1 -> System.out.println("one");
}
}
}

View File

@@ -0,0 +1,16 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void foo(int x) {
switch<caret> (x) {
case 0,1 -> throw new IllegalArgumentException();
case 2,3 -> {
if (Math.random() > 0.5) break;
System.out.println("two or three");
}
case 4 -> System.out.println("four");
default -> {
break;
}
}
}
}