mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
preserve comments on invert if (IDEA-159847)
This commit is contained in:
@@ -318,9 +318,11 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
private static void addAfter(PsiIfStatement ifStatement, PsiStatement thenBranch) throws IncorrectOperationException {
|
||||
if (thenBranch instanceof PsiBlockStatement) {
|
||||
PsiBlockStatement blockStatement = (PsiBlockStatement) thenBranch;
|
||||
PsiStatement[] statements = blockStatement.getCodeBlock().getStatements();
|
||||
if (statements.length > 0) {
|
||||
ifStatement.getParent().addRangeAfter(statements[0], statements[statements.length - 1], ifStatement);
|
||||
final PsiCodeBlock block = blockStatement.getCodeBlock();
|
||||
final PsiElement firstBodyElement = block.getFirstBodyElement();
|
||||
final PsiElement lastBodyElement = block.getLastBodyElement();
|
||||
if (firstBodyElement != null && lastBodyElement != null) {
|
||||
ifStatement.getParent().addRangeAfter(firstBodyElement, lastBodyElement, ifStatement);
|
||||
}
|
||||
} else {
|
||||
ifStatement.getParent().addAfter(thenBranch, ifStatement);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
public void foo() {
|
||||
if (!c) {
|
||||
return;
|
||||
} //comments to restore
|
||||
a();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
public void foo() {
|
||||
<caret>if (c) { //comments to restore
|
||||
a();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user