invert if: don't leave trailing continue stmts (IDEA-197986)

This commit is contained in:
Anna Kozlova
2018-08-28 14:30:55 +03:00
parent 3b82ceb645
commit d0862e4163
3 changed files with 25 additions and 1 deletions
@@ -411,7 +411,7 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
endOffset = controlFlow.getSize();
}
while (endOffset < instructions.size() && instructions.get(endOffset) instanceof GoToInstruction &&
!((GoToInstruction) instructions.get(endOffset)).isReturn && !(controlFlow.getElement(endOffset) instanceof PsiBreakStatement)) {
!((GoToInstruction) instructions.get(endOffset)).isReturn && !(controlFlow.getElement(endOffset) instanceof PsiBreakStatement) && !(controlFlow.getElement(endOffset) instanceof PsiContinueStatement)) {
endOffset = ((BranchingInstruction)instructions.get(endOffset)).offset;
}
@@ -0,0 +1,13 @@
// "Invert 'if' condition" "true"
public class C {
public void test() {
for (int i = 0; i < 42; i++) {
if (i != 7) {
continue;
}
else {
return;
}
}
}
}
@@ -0,0 +1,11 @@
// "Invert 'if' condition" "true"
public class C {
public void test() {
for (int i = 0; i < 42; i++) {
i<caret>f (i == 7) {
return;
}
continue;
}
}
}