mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-119508 pass context PsiFile to ImportFilter
This commit is contained in:
+2
-1
@@ -113,6 +113,7 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe
|
||||
if (classes.length == 0) return Collections.emptyList();
|
||||
List<PsiClass> classList = new ArrayList<PsiClass>(classes.length);
|
||||
boolean isAnnotationReference = myElement.getParent() instanceof PsiAnnotation;
|
||||
final PsiFile file = myElement.getContainingFile();
|
||||
for (PsiClass aClass : classes) {
|
||||
if (isAnnotationReference && !aClass.isAnnotationType()) continue;
|
||||
if (JavaCompletionUtil.isInExcludedPackage(aClass, false)) continue;
|
||||
@@ -120,7 +121,7 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe
|
||||
String qName = aClass.getQualifiedName();
|
||||
if (qName != null) { //filter local classes
|
||||
if (qName.indexOf('.') == -1) continue; //do not show classes from default package)
|
||||
if (qName.endsWith(name) && ImportFilter.shouldImport(qName)) {
|
||||
if (qName.endsWith(name) && ImportFilter.shouldImport(file, qName)) {
|
||||
if (isAccessible(aClass, myElement)) {
|
||||
classList.add(aClass);
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ public class ImportHelper{
|
||||
String className = refClass.getQualifiedName();
|
||||
if (className == null) return true;
|
||||
|
||||
if (!ImportFilter.shouldImport(className)) {
|
||||
if (!ImportFilter.shouldImport(file, className)) {
|
||||
return false;
|
||||
}
|
||||
String packageName = getPackageOrClassName(className);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
@@ -9,11 +11,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
public abstract class ImportFilter {
|
||||
public static final ExtensionPointName<ImportFilter> EP_NAME = new ExtensionPointName<ImportFilter>("com.intellij.importFilter");
|
||||
|
||||
public abstract boolean shouldUseFullyQualifiedName(@NotNull String classQualifiedName);
|
||||
public abstract boolean shouldUseFullyQualifiedName(@Nullable PsiFile targetFile, @NotNull String classQualifiedName);
|
||||
|
||||
public static boolean shouldImport(@NotNull String classQualifiedName) {
|
||||
public static boolean shouldImport(@Nullable PsiFile targetFile, @NotNull String classQualifiedName) {
|
||||
for (ImportFilter filter : EP_NAME.getExtensions()) {
|
||||
if (filter.shouldUseFullyQualifiedName(classQualifiedName)) {
|
||||
if (filter.shouldUseFullyQualifiedName(targetFile, classQualifiedName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user