mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 07:40:42 +07:00
Support BreakConverter in ConvertSwitchToIfIntention
Fixes IDEA-141261 'Replace 'switch' with 'if'' intention produces incorrect code if some 'case' clause contains 'break' statement inside 'if'
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void m(String s, boolean r) {
|
||||
if ("a".equals(s)) {
|
||||
System.out.println("a");
|
||||
if (r) {
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("d");
|
||||
} else {
|
||||
System.out.println("d");
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void m(String s, boolean r) {
|
||||
if ("a".equals(s)) {
|
||||
System.out.println("a");
|
||||
if (r) {
|
||||
} else {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
} else {
|
||||
System.out.println("d");
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(String s, int x) {
|
||||
if (x > 0) {
|
||||
SWITCH:
|
||||
if ("a".equals(s)) {
|
||||
System.out.println("a");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(i);
|
||||
if (i == x) return 0;
|
||||
if (i == x * 2) break;
|
||||
}
|
||||
|
||||
System.out.println("d");
|
||||
} else {
|
||||
System.out.println("d");
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -2,15 +2,13 @@
|
||||
class X {
|
||||
public void doSomething( String value) {
|
||||
//comment1
|
||||
//comment3
|
||||
//comment4
|
||||
//comment5
|
||||
//comment6
|
||||
//comment7
|
||||
//comment8
|
||||
if ("case1".equals(value)) {//comment2
|
||||
} else if ("case2".equals(value)) {
|
||||
} else {
|
||||
//comment3
|
||||
} else if ("case2".equals(value)) {//comment5
|
||||
} else {//comment7
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void m(String s, boolean r) {
|
||||
swi<caret>tch (s) {
|
||||
case "a":
|
||||
System.out.println("a");
|
||||
if (r) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
System.out.println("d");
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void m(String s, boolean r) {
|
||||
swi<caret>tch (s) {
|
||||
case "a":
|
||||
System.out.println("a");
|
||||
if (r) {
|
||||
break;
|
||||
} else {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
default:
|
||||
System.out.println("d");
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace 'switch' with 'if'" "false"
|
||||
class X {
|
||||
void m(String s, boolean r) {
|
||||
swi<caret>tch (s) {
|
||||
case "a":
|
||||
System.out.println("a");
|
||||
if (r) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
System.out.println("d");
|
||||
}
|
||||
System.out.println("oops");
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(String s, int x) {
|
||||
if (x > 0) {
|
||||
SWITCH:
|
||||
swi<caret>tch (s){
|
||||
case "a":
|
||||
System.out.println("a");
|
||||
for(int i=0; i<10; i++) {
|
||||
System.out.println(i);
|
||||
if(i == x) break SWITCH;
|
||||
if(i == x*2) break;
|
||||
}
|
||||
default:
|
||||
System.out.println("d");
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user