IDEA-196805 Warn about switch statement with single 'default'

This commit is contained in:
Tagir Valeev
2018-09-25 14:19:43 +07:00
parent e02761f313
commit 9530731ea5
26 changed files with 488 additions and 39 deletions
@@ -0,0 +1,10 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
if(c == 'a') {
System.out.println("foo");
} else {
}
System.out.println("oops");
}
}
@@ -0,0 +1,9 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
if(c == 'a') {
System.out.println("foo");
}
System.out.println("oops");
}
}
@@ -0,0 +1,11 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
if(c == 'a') {
System.out.println("foo");
return "";
}
System.out.println("oops");
return "";
}
}
@@ -0,0 +1,8 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
if(c == 'a') {
System.out.println("foo");
}
}
}
@@ -0,0 +1,13 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
for(int i=0; i<10; i++)
if(c == 'a') {
System.out.println("foo");
continue;
}
System.out.println("bar");
System.out.println("oops");
return "";
}
}
@@ -0,0 +1,9 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
{
char a, b = c;
}
int b;
}
}
@@ -0,0 +1,6 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
return "foo";
}
}
@@ -0,0 +1,13 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
s<caret>witch (c) {
default:
if(c == 'a') {
System.out.println("foo");
break;
} else break;
}
System.out.println("oops");
}
}
@@ -0,0 +1,14 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
s<caret>witch (c) {
default:
if(c == 'a') {
System.out.println("foo");
break;
}
break;
}
System.out.println("oops");
}
}
@@ -0,0 +1,15 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
s<caret>witch (c) {
default:
if(c == 'a') {
System.out.println("foo");
break;
}
System.out.println("oops");
break;
}
return "";
}
}
@@ -0,0 +1,12 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
s<caret>witch (c) {
default:
if(c == 'a') {
System.out.println("foo");
}
break;
}
}
}
@@ -0,0 +1,16 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
for(int i=0; i<10; i++)
s<caret>witch (c) {
default:
if(c == 'a') {
System.out.println("foo");
break;
}
System.out.println("bar");
}
System.out.println("oops");
return "";
}
}
@@ -0,0 +1,17 @@
// "Unwrap 'switch' statement" "false"
class X {
String test(char c) {
for(int i=0; i<10; i++) {
s<caret>witch (c){
default:
if (c == 'a') {
System.out.println("foo");
break;
}
System.out.println("bar");
}
System.out.println("oops");
}
return "";
}
}
@@ -0,0 +1,10 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
s<caret>witch (c) {
default:
char a, b = c;
}
int b;
}
}
@@ -0,0 +1,9 @@
// "Unwrap 'switch' statement" "true"
class X {
String test(char c) {
s<caret>witch (c) {
default:
return "foo";
}
}
}