mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-10 18:09:38 +07:00
ConvertSwitchToIfIntention: support Java 12 switch statements (no expressions)
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user