fix invert if followed by break bugs (IDEA-38798 & IDEA-112313)

This commit is contained in:
Bas Leijdekkers
2015-02-02 19:38:03 +01:00
parent 3950eb9ccf
commit facac1bd48
5 changed files with 53 additions and 1 deletions

View File

@@ -365,7 +365,8 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
if (endOffset == -1) {
endOffset = controlFlow.getSize();
}
while (endOffset < instructions.size() && instructions.get(endOffset) instanceof GoToInstruction && !((GoToInstruction) instructions.get(endOffset)).isReturn) {
while (endOffset < instructions.size() && instructions.get(endOffset) instanceof GoToInstruction &&
!((GoToInstruction) instructions.get(endOffset)).isReturn && !(controlFlow.getElement(endOffset) instanceof PsiBreakStatement)) {
endOffset = ((BranchingInstruction)instructions.get(endOffset)).offset;
}

View File

@@ -0,0 +1,16 @@
// "Invert 'if' condition" "true"
class A {
public boolean accept() {
boolean xx = true;
switch (1) {
case 0:
if (!xx) {
break;
}
else {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,10 @@
// "Invert 'if' condition" "true"
class A {
void m(boolean b) {
while (true) {
if (!b) {
break;
}
}
}
}

View File

@@ -0,0 +1,14 @@
// "Invert 'if' condition" "true"
class A {
public boolean accept() {
boolean xx = true;
switch (1) {
case 0:
<caret>if (xx) {
return true;
}
break;
}
return false;
}
}

View File

@@ -0,0 +1,11 @@
// "Invert 'if' condition" "true"
class A {
void m(boolean b) {
while (true) {
<caret>if (b) {
continue;
}
break;
}
}
}