mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
move inner to upper level: ensure inserted imports on inner classes are updated (IDEA-200882)
This commit is contained in:
@@ -192,12 +192,17 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
// replace references in a new class to old inner class with references to itself
|
||||
for (PsiReference ref : ReferencesSearch.search(myInnerClass, new LocalSearchScope(newClass), true)) {
|
||||
for (PsiReference ref : ReferencesSearch.search(myInnerClass, new LocalSearchScope(newClass.getContainingFile()), true)) {
|
||||
PsiElement element = ref.getElement();
|
||||
if (element.getParent() instanceof PsiJavaCodeReferenceElement) {
|
||||
PsiJavaCodeReferenceElement parentRef = (PsiJavaCodeReferenceElement)element.getParent();
|
||||
PsiElement parentRefElement = parentRef.resolve();
|
||||
if (parentRefElement instanceof PsiClass) { // reference to inner class inside our inner
|
||||
PsiImportStatementBase insertedImport = PsiTreeUtil.getParentOfType(parentRef, PsiImportStatementBase.class);
|
||||
if (insertedImport != null) {
|
||||
insertedImport.delete();
|
||||
continue;
|
||||
}
|
||||
final PsiReferenceList referenceList = PsiTreeUtil.getTopmostParentOfType(parentRef, PsiReferenceList.class);
|
||||
if (referenceList == null || referenceList.getParent() != newClass) {
|
||||
parentRef.getQualifier().delete();
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package pack1;
|
||||
|
||||
public class Inner {
|
||||
private final MostInner innerMost = new MostInner();
|
||||
|
||||
public class MostInner {}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package pack1;
|
||||
|
||||
public class Outer {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package pack1;
|
||||
|
||||
public class Outer {
|
||||
public static class Inner {
|
||||
private final MostInner innerMost = new MostInner();
|
||||
|
||||
public class MostInner {}
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,11 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
@@ -61,6 +63,12 @@ public class MoveInnerTest extends MultiFileTestCase {
|
||||
doTest(createAction("pack1.Outer.Inner", "Inner", false, null, true, true, null));
|
||||
}
|
||||
|
||||
public void testMostInnerClassImport() {
|
||||
JavaCodeStyleSettings javaCodeStyleSettings = CodeStyle.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
javaCodeStyleSettings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
doTest(createAction("pack1.Outer.Inner", "Inner", false, null, true, true, null));
|
||||
}
|
||||
|
||||
public void testScr22592() {
|
||||
doTest(createAction("xxx.Outer.Inner", "Inner", true, "outer", false, false, null));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user