mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
preserve comments: replace cast with var
This commit is contained in:
@@ -26,6 +26,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class ReplaceCastWithVariableAction extends PsiElementBaseIntentionAction
|
||||
|
||||
final PsiElement toReplace = typeCastExpression.getParent() instanceof PsiParenthesizedExpression ? typeCastExpression.getParent() : typeCastExpression;
|
||||
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
|
||||
toReplace.replace(factory.createExpressionFromText(myReplaceVariableName, toReplace));
|
||||
new CommentTracker().replaceAndRestoreComments(toReplace, factory.createExpressionFromText(myReplaceVariableName, toReplace));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -7,6 +7,7 @@ class FooBar {
|
||||
FooBar foobar = (FooBar)foo;
|
||||
foobar = null;
|
||||
FooBar foobar2 = (FooBar)foo;
|
||||
return foobar2.baz;
|
||||
//comment
|
||||
return foobar2.baz;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ class FooBar {
|
||||
FooBar foobar = (FooBar)foo;
|
||||
foobar = null;
|
||||
FooBar foobar2 = (FooBar)foo;
|
||||
return ((FooBar<caret>)foo).baz;
|
||||
return ((FooBar<caret>)foo//comment
|
||||
).baz;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user