[java-highlighting] IDEA-202570 Unreachable statement inspection should highlight whole switch expression

Also, fixed unreachable statement highlighting in different cases

GitOrigin-RevId: 20b28272b51c77e3413e1ca143222d35199728bd
This commit is contained in:
Tagir Valeev
2021-12-07 18:19:30 +07:00
committed by intellij-monorepo-bot
parent ae33969db0
commit 325edf9af2
10 changed files with 172 additions and 27 deletions

View File

@@ -0,0 +1,62 @@
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;};
}
}