mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
UnwrapSwitchLabelFix: when only one switch branch is reachable
Fixes IDEA-200651 Analysis for 'switch' statements may determine always truthy conditions on branches in addition to always falsy Minor refactoring of reporting in DataFlowInspectionBase
This commit is contained in:
+3
-7
@@ -1,12 +1,8 @@
|
||||
// "Remove switch label '"two"'" "true"
|
||||
// "Unwrap 'switch' statement" "true"
|
||||
class Main {
|
||||
static void fff() {
|
||||
switch ("one") {
|
||||
case "one":
|
||||
System.out.println("one");
|
||||
// quick-fix removes body as well
|
||||
System.out.println("two");
|
||||
}
|
||||
System.out.println("one");
|
||||
System.out.println("two");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Unwrap 'switch' statement" "true"
|
||||
class Main {
|
||||
static void fff(int x) {
|
||||
if (x == 5) {
|
||||
System.out.println("five-ten-fifteen"); //5
|
||||
System.out.println("six"); //6
|
||||
System.out.println("seven"); //7
|
||||
//other
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
fff();
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
// "Remove switch label '"two"'" "true"
|
||||
// "Unwrap 'switch' statement" "true"
|
||||
class Main {
|
||||
static void fff() {
|
||||
switch ("one") {
|
||||
case "one":
|
||||
case "<caret>one":
|
||||
System.out.println("one");
|
||||
case "<caret>two": // quick-fix removes body as well
|
||||
case "two":
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "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: 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
fff();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user