mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
CommentTracker#makeRangeUnchanged; more comment fixes for InvertIfCondition
This commit is contained in:
+2
-2
@@ -197,8 +197,8 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
PsiElement lastElement = codeBlock.getLastBodyElement();
|
||||
if (firstElement != null && lastElement != null) {
|
||||
ifStatement.getParent().addRangeAfter(firstElement, lastElement, ifStatement);
|
||||
ct.markRangeUnchanged(firstElement, lastElement);
|
||||
}
|
||||
ct.markUnchanged(thenBranch);
|
||||
} else {
|
||||
if (!(thenBranch instanceof PsiReturnStatement)) {
|
||||
ifStatement = addAfterWithinCodeBlock(ifStatement, thenBranch);
|
||||
@@ -302,7 +302,7 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (thenBranch instanceof PsiBlockStatement) {
|
||||
if (thenBranch instanceof PsiBlockStatement) {
|
||||
PsiStatement[] statements = ((PsiBlockStatement) thenBranch).getCodeBlock().getStatements();
|
||||
if (statements.length > 0 && statements[statements.length - 1] instanceof PsiContinueStatement) {
|
||||
new CommentTracker().deleteAndRestoreComments(statements[statements.length - 1]);
|
||||
|
||||
@@ -4,6 +4,7 @@ class A {
|
||||
public void foo() {
|
||||
String value ="not-null";
|
||||
|
||||
// Another comment
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
class A {
|
||||
void f(){
|
||||
while (true) {
|
||||
if (false) //comment
|
||||
{
|
||||
//comment
|
||||
if (false) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,6 +7,6 @@ class A {
|
||||
<caret>if (value != null) {
|
||||
System.out.println(value);
|
||||
// Comment gets deleted.
|
||||
}
|
||||
} // Another comment
|
||||
}
|
||||
}
|
||||
+15
@@ -79,6 +79,18 @@ public class CommentTracker {
|
||||
return element;
|
||||
}
|
||||
|
||||
public void markRangeUnchanged(@NotNull PsiElement firstElement, @NotNull PsiElement lastElement) {
|
||||
checkState();
|
||||
PsiElement e;
|
||||
for (e = firstElement; e != null && e != lastElement; e = e.getNextSibling()) {
|
||||
addIgnored(e);
|
||||
}
|
||||
if (e == null) {
|
||||
throw new IllegalArgumentException("Elements must be siblings: " + firstElement + " and " + lastElement);
|
||||
}
|
||||
addIgnored(lastElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes given PsiElement collecting all the comments inside it.
|
||||
*
|
||||
@@ -168,6 +180,9 @@ public class CommentTracker {
|
||||
if (anchor instanceof PsiVariable && anchor.getParent() instanceof PsiDeclarationStatement) {
|
||||
anchor = anchor.getParent();
|
||||
}
|
||||
if (anchor instanceof PsiStatement && (anchor.getParent() instanceof PsiIfStatement || anchor.getParent() instanceof PsiLoopStatement)) {
|
||||
anchor = anchor.getParent();
|
||||
}
|
||||
if (anchor == null) anchor = result;
|
||||
insertCommentsBefore(anchor);
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user