mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
invert if: don't insert continue outside while loop (IDEA-175283)
This commit is contained in:
+1
-1
@@ -218,7 +218,7 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
while (element != null && !(element instanceof PsiStatement)) element = element.getParent();
|
||||
|
||||
if (element != null && element.getParent() instanceof PsiForStatement && ((PsiForStatement)element.getParent()).getUpdate() == element ||
|
||||
element instanceof PsiWhileStatement && flow.getStartOffset(element) == endOffset ||
|
||||
element instanceof PsiWhileStatement && flow.getStartOffset(element) == endOffset && PsiTreeUtil.isAncestor(element, ifStatement, true) ||
|
||||
element instanceof PsiForeachStatement && flow.getStartOffset(element) + 1 == endOffset) {
|
||||
PsiStatement statement = factory.createStatementFromText("continue;", ifStatement);
|
||||
statement = (PsiStatement)codeStyle.reformat(statement);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
public void foo() {
|
||||
if (!c) {
|
||||
}
|
||||
else {
|
||||
a();
|
||||
}
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
public void foo() {
|
||||
<caret>if (c) a();
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user