mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
restore comments on Insert New
This commit is contained in:
@@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InsertNewFix implements IntentionAction {
|
||||
@@ -61,13 +62,14 @@ public class InsertNewFix implements IntentionAction {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(myMethodCall.getProject()).getElementFactory();
|
||||
PsiNewExpression newExpression = (PsiNewExpression)factory.createExpressionFromText("new X()",null);
|
||||
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
PsiJavaCodeReferenceElement classReference = newExpression.getClassReference();
|
||||
assert classReference != null;
|
||||
classReference.replace(factory.createClassReferenceElement(myClass));
|
||||
PsiExpressionList argumentList = newExpression.getArgumentList();
|
||||
assert argumentList != null;
|
||||
argumentList.replace(myMethodCall.getArgumentList());
|
||||
myMethodCall.replace(newExpression);
|
||||
argumentList.replace(tracker.markUnchanged(myMethodCall.getArgumentList()));
|
||||
tracker.replaceAndRestoreComments(myMethodCall, newExpression);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-1
@@ -1,7 +1,11 @@
|
||||
// "Insert new" "true"
|
||||
class a {
|
||||
void f() {
|
||||
<caret>new RuntimeException();
|
||||
//c1
|
||||
new RuntimeException(
|
||||
//c2
|
||||
)//c3
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -1,7 +1,11 @@
|
||||
// "Insert new" "true"
|
||||
class a {
|
||||
void f() {
|
||||
<caret>RuntimeException();
|
||||
<caret>RuntimeException//c1
|
||||
(
|
||||
//c2
|
||||
)//c3
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user