mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
InvertIfConditionAction: preserve comments after last statement
Fixes IDEA-153371 invert 'if' condition deletes comment lines
This commit is contained in:
@@ -209,7 +209,11 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
while (firstElement.getPrevSibling() instanceof PsiWhiteSpace || firstElement.getPrevSibling() instanceof PsiComment) {
|
||||
firstElement = firstElement.getPrevSibling();
|
||||
}
|
||||
ifStatement.getParent().addRangeAfter(firstElement, statements[statements.length - 1], ifStatement);
|
||||
PsiElement lastElement = statements[statements.length - 1];
|
||||
while (lastElement.getNextSibling() instanceof PsiWhiteSpace || lastElement.getNextSibling() instanceof PsiComment) {
|
||||
lastElement = lastElement.getNextSibling();
|
||||
}
|
||||
ifStatement.getParent().addRangeAfter(firstElement, lastElement, ifStatement);
|
||||
}
|
||||
} else {
|
||||
if (!(thenBranch instanceof PsiReturnStatement)) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
// IDEA-153371
|
||||
public void foo() {
|
||||
String value ="not-null";
|
||||
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(value);
|
||||
// Comment gets deleted.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
public void foo() {
|
||||
String value ="not-null";
|
||||
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
/* block*/
|
||||
// Before
|
||||
System.out.println(value);
|
||||
/* inside */
|
||||
System.out.println(value);
|
||||
// After
|
||||
/* end block*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
// IDEA-153371
|
||||
public void foo() {
|
||||
String value ="not-null";
|
||||
|
||||
<caret>if (value != null) {
|
||||
System.out.println(value);
|
||||
// Comment gets deleted.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
public void foo() {
|
||||
String value ="not-null";
|
||||
|
||||
<caret>if (value != null) {
|
||||
/* block*/
|
||||
// Before
|
||||
System.out.println(value);
|
||||
/* inside */
|
||||
System.out.println(value);
|
||||
// After
|
||||
/* end block*/
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user