DeleteSwitchLabelFix: delete unreachable switch branch

Fixes IDEA-199692 Quickfix to delete unreachable switch branch reported by "constant conditions & exceptions"
This commit is contained in:
Tagir Valeev
2018-10-01 14:54:36 +07:00
parent 27b2efd106
commit 5fc3612fa9
12 changed files with 267 additions and 5 deletions
@@ -0,0 +1,16 @@
// "Remove switch branch '"baz"'" "true"
class Main {
public void test() {
switch ("foo") {
case "qux":
case "bar":
class Foo {}
int i;
i = 2;
System.out.println("hello"+new Foo()+i);
//oops
default:
System.out.println("oops");
}
}
}
@@ -0,0 +1,19 @@
// "Remove switch label '"qux"'" "true"
class Main {
public void test() {
switch ("foo") {
case "baz":
int i = 1;
class Foo {}
System.out.println(i);
break;
/*comment*/
case "bar":
i = 2;
System.out.println("hello"+new Foo()+i);
//oops
default:
System.out.println("oops");
}
}
}
@@ -0,0 +1,19 @@
// "Remove switch label '"bar"'" "true"
class Main {
public void test() {
switch ("foo") {
case "baz":
int i = 1;
class Foo {}
System.out.println(i);
break;
case "qux":
// comment
i = 2;
System.out.println("hello"+new Foo()+i);
//oops
default:
System.out.println("oops");
}
}
}
@@ -0,0 +1,11 @@
// "Remove switch branch '"bar"'" "true"
class Main {
public void test() {
switch ("foo") {
case "baz":
System.out.println("foo");
break;
//oops
}
}
}
@@ -0,0 +1,19 @@
// "Remove switch branch '"baz"'" "true"
class Main {
public void test() {
switch ("foo") {
case "<caret>baz":
int i = 1;
class Foo {}
System.out.println(i);
break;
case "qux":
case "bar":
i = 2;
System.out.println("hello"+new Foo()+i);
//oops
default:
System.out.println("oops");
}
}
}
@@ -0,0 +1,19 @@
// "Remove switch label '"qux"'" "true"
class Main {
public void test() {
switch ("foo") {
case "baz":
int i = 1;
class Foo {}
System.out.println(i);
break;
case "<caret>qux" /*comment*/:
case "bar":
i = 2;
System.out.println("hello"+new Foo()+i);
//oops
default:
System.out.println("oops");
}
}
}
@@ -0,0 +1,20 @@
// "Remove switch label '"bar"'" "true"
class Main {
public void test() {
switch ("foo") {
case "baz":
int i = 1;
class Foo {}
System.out.println(i);
break;
case "qux":
case "<caret>bar" // comment
:
i = 2;
System.out.println("hello"+new Foo()+i);
//oops
default:
System.out.println("oops");
}
}
}
@@ -0,0 +1,15 @@
// "Remove switch branch '"bar"'" "true"
class Main {
public void test() {
switch ("foo") {
case "baz":
System.out.println("foo");
break;
case "<caret>bar":
int i = 2;
class Foo {}
System.out.println("hello"+new Foo()+i);
//oops
}
}
}