Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/switchExpressions/DeadCode.java
Tagir Valeev 325edf9af2 [java-highlighting] IDEA-202570 Unreachable statement inspection should highlight whole switch expression
Also, fixed unreachable statement highlighting in different cases

GitOrigin-RevId: 20b28272b51c77e3413e1ca143222d35199728bd
2021-12-08 02:48:47 +00:00

62 lines
1.5 KiB
Java

public class DeadCode {
private static String m1(int n) {
return "";
<error descr="Unreachable statement">return</error> switch (1) {
default -> "x";
};
}
private static String m2(int n) {
return "";
<error descr="Unreachable statement">int x = switch (1) {
default -> 0;
};</error>
}
private static String m3(int n) {
int x;
return "";
<error descr="Unreachable statement">x = switch (1) {
default -> 0;
};</error>
}
private static String m4(int n) {
return "";
<error descr="Unreachable statement">throw</error> switch (1) {
default -> new RuntimeException();
};
}
private static String m5(int n) {
return "";
<error descr="Unreachable statement">try</error> (AutoCloseable x = switch(1) {default -> () -> {};}) {} catch (Exception e) {
e.printStackTrace();
}
}
private static String m6(int n) {
return "";
<error descr="Unreachable statement">synchronized</error> (switch(1) {default -> "";}) {
System.out.println("");
}
}
private static String m7(int n) {
return "";
<error descr="Unreachable statement">if</error>(switch (1) {default -> true;}) {}
}
private static String m8(int n) {
return switch (n) {
default:
yield "x";
<error descr="Unreachable statement">yield</error> switch(1) { default -> ""; };
};
}
private static String m9() {
return "";
<error descr="Unreachable statement">assert</error> switch(1) {default -> true;};
}
}