mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
removing static imports in "safe delete"
This commit is contained in:
@@ -29,12 +29,12 @@ public abstract class ImportSearcher {
|
||||
* @return found import or null
|
||||
*/
|
||||
@Nullable
|
||||
public abstract PsiElement findImport(PsiElement element);
|
||||
public abstract PsiElement findImport(PsiElement element, boolean onlyNonStatic);
|
||||
|
||||
@Nullable
|
||||
public static PsiElement getImport(PsiElement element) {
|
||||
public static PsiElement getImport(PsiElement element, boolean onlyNonStatic) {
|
||||
for (ImportSearcher searcher : EP_NAME.getExtensions()) {
|
||||
PsiElement anImport = searcher.findImport(element);
|
||||
PsiElement anImport = searcher.findImport(element, onlyNonStatic);
|
||||
if (anImport != null) return anImport;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,24 +15,27 @@
|
||||
*/
|
||||
package com.intellij.refactoring.safeDelete;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiImportStatement;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class JavaImportSearcher extends ImportSearcher {
|
||||
@Override
|
||||
public PsiElement findImport(PsiElement element) {
|
||||
public PsiElement findImport(PsiElement element, boolean onlyNonStatic) {
|
||||
final PsiFile containingFile = element.getContainingFile();
|
||||
if (containingFile instanceof PsiJavaFile) {
|
||||
if (!(containingFile instanceof PsiJavaFile)) return null;
|
||||
|
||||
if (onlyNonStatic) {
|
||||
PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiImportStatement) {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return PsiTreeUtil.getParentOfType(element, PsiImportStatementBase.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,15 +329,15 @@ public class JavaSafeDeleteProcessor extends SafeDeleteProcessorDelegateBase {
|
||||
}
|
||||
}
|
||||
LOG.assertTrue(element.getTextRange() != null);
|
||||
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, psiClass, isInImport(element)));
|
||||
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, psiClass, isInNonStaticImport(element)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isInImport(PsiElement element) {
|
||||
return ImportSearcher.getImport(element) != null;
|
||||
private static boolean isInNonStaticImport(PsiElement element) {
|
||||
return ImportSearcher.getImport(element, true) != null;
|
||||
}
|
||||
|
||||
private static boolean containsOnlyPrivates(final PsiClass aClass) {
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class SafeDeleteReferenceJavaDeleteUsageInfo extends SafeDeleteReferenceS
|
||||
if (isSafeDelete()) {
|
||||
PsiElement element = getElement();
|
||||
LOG.assertTrue(element != null);
|
||||
PsiElement importStatement = ImportSearcher.getImport(element);
|
||||
PsiElement importStatement = ImportSearcher.getImport(element, false);
|
||||
if (importStatement != null) {
|
||||
importStatement.delete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user