mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +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();
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@
|
||||
<editorNotificationProvider implementation="org.jetbrains.plugins.groovy.annotator.ConfigureGroovyLibraryNotificationProvider"/>
|
||||
<refactoring.introduceParameterMethodUsagesProcessor implementation="org.jetbrains.plugins.groovy.refactoring.introduce.parameter.java2groovy.GroovyIntroduceParameterMethodUsagesProcessor"/>
|
||||
<refactoring.changeSignatureUsageProcessor implementation="org.jetbrains.plugins.groovy.refactoring.changeSignature.GrChangeSignatureUsageProcessor" id="groovyProcessor" order="before javaProcessor"/>
|
||||
<safeDelete.ImportSearcher implementation="org.jetbrains.plugins.groovy.refactoring.safeDelete.GroovyImportSearcher"/>
|
||||
<safeDelete.importSearcher implementation="org.jetbrains.plugins.groovy.refactoring.safeDelete.GroovyImportSearcher"/>
|
||||
|
||||
<constantExpressionEvaluator language="Groovy" implementationClass="org.jetbrains.plugins.groovy.lang.psi.util.GroovyConstantExpressionEvaluator"/>
|
||||
<annotationSupport language="Groovy" implementationClass="org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.annotation.GroovyAnnotationSupport"/>
|
||||
|
||||
+5
-2
@@ -27,10 +27,13 @@ import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatem
|
||||
*/
|
||||
public class GroovyImportSearcher extends ImportSearcher {
|
||||
@Override
|
||||
public PsiElement findImport(PsiElement element) {
|
||||
public PsiElement findImport(PsiElement element, boolean onlyNonStatic) {
|
||||
PsiFile file = element.getContainingFile();
|
||||
if (file instanceof GroovyFile) {
|
||||
return PsiTreeUtil.getParentOfType(element, GrImportStatement.class);
|
||||
GrImportStatement anImport = PsiTreeUtil.getParentOfType(element, GrImportStatement.class);
|
||||
if (!(anImport == null || anImport.isStatic() && onlyNonStatic)) {
|
||||
return anImport;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1021,7 +1021,7 @@
|
||||
<refactoring.moveInnerHandler language="JAVA" implementationClass="com.intellij.refactoring.move.moveInner.MoveJavaInnerHandler" id="java"/>
|
||||
|
||||
<refactoring.safeDeleteProcessor implementation="com.intellij.refactoring.safeDelete.JavaSafeDeleteProcessor" id="javaProcessor"/>
|
||||
<safeDelete.ImportSearcher implementation="com.intellij.refactoring.safeDelete.JavaImportSearcher"/>
|
||||
<safeDelete.importSearcher implementation="com.intellij.refactoring.safeDelete.JavaImportSearcher"/>
|
||||
|
||||
<refactoring.introduceParameterMethodUsagesProcessor implementation="com.intellij.refactoring.introduceParameter.JavaIntroduceParameterMethodUsagesProcessor"/>
|
||||
<refactoring.changeSignatureUsageProcessor implementation="com.intellij.refactoring.changeSignature.JavaChangeSignatureUsageProcessor" id="javaProcessor"/>
|
||||
|
||||
Reference in New Issue
Block a user