Extract common conjunct from if-else chain in ExtractIfConditionAction

Fixes IDEA-179499 New inspection: Should break out common conjunct from "if / else if"
This commit is contained in:
Tagir Valeev
2018-04-07 09:08:57 +03:00
parent 1916b3a079
commit 83ebaa7f64
9 changed files with 136 additions and 17 deletions
@@ -1,15 +1,13 @@
// "Extract if (a)" "true"
class TestThreadInspection {
void f(boolean a, boolean b, boolean c){
if (a)
if (a) {
if (b) {
System.out.println("a&b");//first comment
} else {
if (c) {
System.out.println("c");
}
} else if (c) {
System.out.println("c");
}
else if (c) {
} else if (c) {
System.out.println("c");
}
}
@@ -0,0 +1,13 @@
// "Extract if (a)" "true"
class Test {
void f(boolean a, boolean b, boolean c){
/*2*/
if (a) {
if (b) {
System.out.println("a&b");//first comment
} else if (c) {
System.out.println("a&c"); // three
}
}
}
}
@@ -0,0 +1,17 @@
// "Extract if (a)" "true"
class Test {
void f(boolean a, boolean b, boolean c, boolean d){
//a
if (a) {
if (b) {
System.out.println("a&b");//first comment
} else if (c) {
System.out.println("a&c");//ac
} else {
System.out.println("a");//a
}
} else if (d) {
System.out.println("d");//d
}
}
}
@@ -0,0 +1,17 @@
// "Extract if (a)" "true"
class Test {
void f(boolean a, boolean b, boolean c, boolean d){
//a
if (a) {
if (b) {
System.out.println("a&b");//first comment
} else {
System.out.println("a");//a
}
} else if (a && c) {
System.out.println("a&c");//ac
} else if (a && d) {
System.out.println("a&d");//ad
}
}
}
@@ -1,13 +1,13 @@
// "Extract if (a)" "true"
class TestThreadInspection {
void f(boolean a, boolean b, boolean c){
if (a)
if (a) {
if (b) {
System.out.println("a&b");
} else {
System.out.println("c");
}
else {
} else {
System.out.println("c");
}
}
@@ -0,0 +1,10 @@
// "Extract if (a)" "true"
class Test {
void f(boolean a, boolean b, boolean c){
if (<caret>a && b)
System.out.println("a&b");//first comment
else if (a && c/*2*/) {
System.out.println("a&c"); // three
}
}
}
@@ -0,0 +1,16 @@
// "Extract if (a)" "true"
class Test {
void f(boolean a, boolean b, boolean c, boolean d){
if (<caret>a && b)
System.out.println("a&b");//first comment
else if (a && c) {
System.out.println("a&c");//ac
}
else if (a) {
System.out.println("a");//a
}
else if (d) {
System.out.println("d");//d
}
}
}
@@ -0,0 +1,16 @@
// "Extract if (a)" "true"
class Test {
void f(boolean a, boolean b, boolean c, boolean d){
if (<caret>a && b)
System.out.println("a&b");//first comment
else if (a) {
System.out.println("a");//a
}
else if (a && c) {
System.out.println("a&c");//ac
}
else if (a && d) {
System.out.println("a&d");//ad
}
}
}