mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
ConvertSwitchToIfIntention: fixes after review IDEA-CR-37311:
1. Do not suggest intention if `default` case is not the last one and fallthrough is possible into or out of that case 2. Generate a code-block if side-effect should be extracted to variable
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(int i) {
|
||||
if (i > 0) {
|
||||
int i1 = ++i;
|
||||
if (i1 == 1) {
|
||||
System.out.println(1);
|
||||
|
||||
System.out.println(2);
|
||||
} else if (i1 == 2) {
|
||||
System.out.println(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void m(String s) {
|
||||
if ("foo".equals(s)) {
|
||||
System.out.println(1);
|
||||
} else if ("bar".equals(s)) {
|
||||
System.out.println(3);
|
||||
} else {
|
||||
System.out.println(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(int i) {
|
||||
if (i > 0)
|
||||
sw<caret>itch (++i) {
|
||||
case 1:
|
||||
System.out.println(1);
|
||||
case 2:
|
||||
System.out.println(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void m(String s) {
|
||||
swi<caret>tch (s) {
|
||||
case "foo":
|
||||
System.out.println(1);
|
||||
break;
|
||||
default:
|
||||
System.out.println(2);
|
||||
break;
|
||||
case "bar":
|
||||
System.out.println(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace 'switch' with 'if'" "false"
|
||||
class X {
|
||||
void m(String s) {
|
||||
swi<caret>tch (s) {
|
||||
case "foo":
|
||||
System.out.println(1);
|
||||
default:
|
||||
System.out.println(2);
|
||||
break;
|
||||
case "bar":
|
||||
System.out.println(3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace 'switch' with 'if'" "false"
|
||||
class X {
|
||||
void m(String s) {
|
||||
swi<caret>tch (s) {
|
||||
case "foo":
|
||||
System.out.println(1);
|
||||
break;
|
||||
default:
|
||||
System.out.println(2);
|
||||
case "bar":
|
||||
System.out.println(3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user