mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
restore comments on convert to local (IDEA-178942)
This commit is contained in:
@@ -33,6 +33,7 @@ import com.intellij.util.IJSwingUtilities;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -154,14 +155,20 @@ public abstract class BaseConvertToLocalQuickFix<V extends PsiVariable> implemen
|
||||
return WriteAction.compute(() -> {
|
||||
final PsiElement newDeclaration = moveDeclaration(elementFactory, localName, variable, initializer, action, references);
|
||||
if (delete) {
|
||||
beforeDelete(project, variable, newDeclaration);
|
||||
variable.normalizeDeclaration();
|
||||
variable.delete();
|
||||
deleteSourceVariable(project, variable, newDeclaration);
|
||||
}
|
||||
return newDeclaration;
|
||||
});
|
||||
}
|
||||
|
||||
protected void deleteSourceVariable(@NotNull Project project, @NotNull V variable, PsiElement newDeclaration) {
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
beforeDelete(project, variable, newDeclaration);
|
||||
variable.normalizeDeclaration();
|
||||
tracker.delete(variable);
|
||||
tracker.insertCommentsBefore(newDeclaration);
|
||||
}
|
||||
|
||||
protected PsiElement moveDeclaration(PsiElementFactory elementFactory,
|
||||
String localName,
|
||||
V variable,
|
||||
|
||||
@@ -70,12 +70,7 @@ public class FieldCanBeLocalInspection extends FieldCanBeLocalInspectionBase {
|
||||
}
|
||||
if (element != null) {
|
||||
final PsiElement finalElement = element;
|
||||
Runnable runnable = () -> {
|
||||
beforeDelete(project, variable, finalElement);
|
||||
variable.normalizeDeclaration();
|
||||
variable.delete();
|
||||
};
|
||||
ApplicationManager.getApplication().runWriteAction(runnable);
|
||||
ApplicationManager.getApplication().runWriteAction(() -> deleteSourceVariable(project, variable, finalElement));
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ class ITest {
|
||||
|
||||
public IntelliJBugConvertToLocal(int x, int z) {
|
||||
|
||||
//my comment to keep in code
|
||||
ArrayList<String> mayBeLocal = new ArrayList<String>();
|
||||
if (x == 5) {
|
||||
mayBeLocal.add("jjj");
|
||||
|
||||
@@ -3,7 +3,7 @@ import java.util.ArrayList;
|
||||
|
||||
class ITest {
|
||||
|
||||
private ArrayList<String> may<caret>BeLocal = new ArrayList<String>();
|
||||
private ArrayList<String> may<caret>BeLocal = new ArrayList<String>(); //my comment to keep in code
|
||||
|
||||
public IntelliJBugConvertToLocal(int x, int z) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user