mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
invert if: fix parent ifStatement (IDEA-191327)
This commit is contained in:
+5
@@ -213,6 +213,11 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
PsiStatement statement = factory.createStatementFromText("return;", ifStatement);
|
||||
statement = (PsiStatement) codeStyle.reformat(statement);
|
||||
if (thenBranch instanceof PsiBlockStatement) {
|
||||
if (ifStatement.getParent() instanceof PsiIfStatement) {
|
||||
ifStatement = (PsiIfStatement)wrapWithCodeBlock(ifStatement);
|
||||
thenBranch = ifStatement.getThenBranch();
|
||||
assert thenBranch != null;
|
||||
}
|
||||
PsiCodeBlock codeBlock = ((PsiBlockStatement)thenBranch).getCodeBlock();
|
||||
PsiElement firstElement = codeBlock.getFirstBodyElement();
|
||||
PsiElement lastElement = codeBlock.getLastBodyElement();
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
public void foo(boolean c, boolean c2) {
|
||||
if (c) a();
|
||||
else {
|
||||
if (c2) {
|
||||
return;
|
||||
}
|
||||
b();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
public void foo(boolean c, boolean c2) {
|
||||
if (c) a();
|
||||
else if (!c<caret>2) b();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user