mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-05 21:00:59 +07:00
Merge SwitchStatementWithSingleDefaultInspection into SwitchStatementWithTooFewBranches
Fixes IDEA-199499 Improve "Replace 'switch' with 'if'" action and make it a quick-fix for "Switch has too few branches" Now default is not counted as branch in SwitchStatementWithTooFewBranches
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(String s, boolean r) {
|
||||
if (r) return 1;
|
||||
else if ("a".equals(s)) {
|
||||
return 1;
|
||||
} else if ("b".equals(s)) {
|
||||
return 2;
|
||||
} else {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(String s, boolean r) {
|
||||
if ("a".equals(s)) {
|
||||
return 1;
|
||||
} else if ("b".equals(s)) {
|
||||
return 2;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,7 @@ class X {
|
||||
if (r) {
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("d");
|
||||
} else {
|
||||
System.out.println("d");
|
||||
}
|
||||
System.out.println("d");
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,15 @@ class X {
|
||||
int m(String s, int x) {
|
||||
if (x > 0) {
|
||||
SWITCH:
|
||||
if ("a".equals(s)) {
|
||||
System.out.println("a");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(i);
|
||||
if (i == x) return 0;
|
||||
if (i == x * 2) break;
|
||||
{
|
||||
if ("a".equals(s)) {
|
||||
System.out.println("a");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(i);
|
||||
if (i == x) return 0;
|
||||
if (i == x * 2) break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("d");
|
||||
} else {
|
||||
System.out.println("d");
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(String s, boolean r) {
|
||||
//ignore
|
||||
if ("x".equals(s)) {
|
||||
System.out.println("foo");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void m(String s, boolean r) {
|
||||
if (r) {
|
||||
if ("a".equals(s)) {
|
||||
System.out.println("a");
|
||||
}
|
||||
System.out.println("d");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ class X {
|
||||
//comment1
|
||||
//comment4
|
||||
//comment6
|
||||
//comment7
|
||||
//comment8
|
||||
if ("case1".equals(value)) {//comment2
|
||||
//comment3
|
||||
} else if ("case2".equals(value)) {//comment5
|
||||
} else {//comment7
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
abstract class Test {
|
||||
abstract Object getObject();
|
||||
|
||||
void foo() {
|
||||
if (RuntimeException.class.equals(getObject().getClass())) {
|
||||
System.out.println("RuntimeException");
|
||||
} else {
|
||||
System.out.println("Other");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(String s, boolean r) {
|
||||
if (r) return 1;
|
||||
else
|
||||
swi<caret>tch (s) {
|
||||
case "a":
|
||||
return 1;
|
||||
case "b":
|
||||
return 2;
|
||||
default:
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(String s, boolean r) {
|
||||
swi<caret>tch (s) {
|
||||
case "a":
|
||||
return 1;
|
||||
case "b":
|
||||
return 2;
|
||||
default:
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
int m(String s, boolean r) {
|
||||
switc<caret>h(s) {
|
||||
case "x":
|
||||
System.out.println("foo");
|
||||
break;
|
||||
default: {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void m(String s, boolean r) {
|
||||
if (r)
|
||||
swi<caret>tch (s) {
|
||||
case "a":
|
||||
System.out.println("a");
|
||||
default:
|
||||
System.out.println("d");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
abstract class Test {
|
||||
abstract Object getObject();
|
||||
|
||||
void foo() {
|
||||
<caret>switch(getObject().getClass()) {
|
||||
case RuntimeException.class:
|
||||
System.out.println("RuntimeException");
|
||||
break;
|
||||
default:
|
||||
System.out.println("Other");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user