mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup: make fields final (part of IJPL-210489 rework auto-imports hints to show in more places)
GitOrigin-RevId: 5c9038a585082a28b176590230826c23b6d6791d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
164a90ccda
commit
3a462749b6
+34
-34
@@ -55,8 +55,8 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe
|
||||
private final PsiClass[] myClassesToImport;
|
||||
private final boolean myHasUnresolvedImportWhichCanImport;
|
||||
private final PsiFile myContainingPsiFile;
|
||||
private boolean myInContent;
|
||||
private ThreeState extensionsAllowToChangeFileSilently;
|
||||
private final boolean myInContent;
|
||||
private final ThreeState extensionsAllowToChangeFileSilently;
|
||||
|
||||
@RequiresBackgroundThread
|
||||
@RequiresReadLock
|
||||
@@ -67,7 +67,10 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe
|
||||
myReferenceElement = referenceElement;
|
||||
myReference = reference;
|
||||
myContainingPsiFile = referenceElement.getContainingFile();
|
||||
myClassesToImport = calcClassesToImport();
|
||||
CalcInfo calcInfo = calcClassesToImport();
|
||||
myClassesToImport = calcInfo.classesToImport();
|
||||
myInContent = calcInfo.inContent();
|
||||
extensionsAllowToChangeFileSilently = calcInfo.extensionsAllowToChangeFileSilently();
|
||||
String firstName;
|
||||
myHasUnresolvedImportWhichCanImport = myClassesToImport.length != 0
|
||||
&& (firstName = myClassesToImport[0].getName()) != null
|
||||
@@ -126,21 +129,23 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe
|
||||
return myReference;
|
||||
}
|
||||
|
||||
private PsiClass @NotNull [] calcClassesToImport() {
|
||||
private record CalcInfo(@NotNull PsiClass @NotNull [] classesToImport, ThreeState extensionsAllowToChangeFileSilently, boolean inContent) {}
|
||||
@RequiresBackgroundThread
|
||||
private CalcInfo calcClassesToImport() {
|
||||
ApplicationManager.getApplication().assertIsNonDispatchThread();
|
||||
ApplicationManager.getApplication().assertReadAccessAllowed();
|
||||
PsiFile psiFile = myContainingPsiFile;
|
||||
VirtualFile virtualFile = psiFile == null ? null : psiFile.getVirtualFile();
|
||||
Project project = psiFile == null ? null : psiFile.getProject();
|
||||
boolean myInContent = virtualFile != null && ModuleUtilCore.projectContainsFile(project, virtualFile, false);
|
||||
ThreeState extensionsAllowToChangeFileSilently = virtualFile == null ? ThreeState.UNSURE : SilentChangeVetoer.extensionsAllowToChangeFileSilently(project, virtualFile);
|
||||
CalcInfo empty = new CalcInfo(PsiClass.EMPTY_ARRAY, extensionsAllowToChangeFileSilently, myInContent);
|
||||
if (psiFile == null) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
return empty;
|
||||
}
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
myInContent = virtualFile != null && ModuleUtilCore.projectContainsFile(psiFile.getProject(), virtualFile, false);
|
||||
|
||||
extensionsAllowToChangeFileSilently = virtualFile == null ? ThreeState.UNSURE : SilentChangeVetoer.extensionsAllowToChangeFileSilently(psiFile.getProject(), virtualFile);
|
||||
|
||||
PsiElement referenceElement;
|
||||
if (!myReferenceElement.isValid() || (referenceElement = myReference.getElement()) != myReferenceElement && !referenceElement.isValid()) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
return empty;
|
||||
}
|
||||
if (myReference instanceof PsiJavaReference ref) {
|
||||
JavaResolveResult result = ref.advancedResolve(true);
|
||||
@@ -148,40 +153,34 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe
|
||||
// already imported
|
||||
// can happen when e.g., class name happened to be in a method position
|
||||
if (element instanceof PsiClass && (result.isValidResult() || result.getCurrentFileResolveScope() instanceof PsiImportStatement)) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
||||
String name = getReferenceName(myReference);
|
||||
if (name == null) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if (!canReferenceClass(myReference)) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
Project project = psiFile.getProject();
|
||||
|
||||
PsiElement parent = myReferenceElement.getParent();
|
||||
if (parent instanceof PsiNewExpression newExpression && newExpression.getQualifier() != null) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
if (name == null ||
|
||||
!canReferenceClass(myReference) ||
|
||||
parent instanceof PsiNewExpression newExpression && newExpression.getQualifier() != null) {
|
||||
return empty;
|
||||
}
|
||||
|
||||
if (parent instanceof PsiReferenceExpression ref) {
|
||||
PsiExpression expression = ref.getQualifierExpression();
|
||||
if (expression != null && expression != myReferenceElement) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
||||
if (psiFile instanceof PsiJavaCodeReferenceCodeFragment ref && !ref.isClassesAccepted()) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
return empty;
|
||||
}
|
||||
|
||||
GlobalSearchScope scope = psiFile.getResolveScope();
|
||||
PsiClass[] classes = PsiShortNamesCache.getInstance(project).getClassesByName(name, scope);
|
||||
if (classes.length == 0) return PsiClass.EMPTY_ARRAY;
|
||||
if (classes.length == 0) {
|
||||
return empty;
|
||||
}
|
||||
List<PsiClass> classList = new ArrayList<>(classes.length);
|
||||
boolean isAnnotationReference = myReferenceElement.getParent() instanceof PsiAnnotation;
|
||||
for (PsiClass aClass : classes) {
|
||||
@@ -210,16 +209,17 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe
|
||||
filterAlreadyImportedButUnresolved(classList, psiFile);
|
||||
|
||||
if (classList.isEmpty() || isReferenceNameForbiddenForAutoImport()) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
classes = PsiClass.EMPTY_ARRAY;
|
||||
}
|
||||
else {
|
||||
if (classList.size() > 1) {
|
||||
reduceSuggestedClassesBasedOnDependencyRuleViolation(classList, psiFile);
|
||||
}
|
||||
|
||||
if (classList.size() > 1) {
|
||||
reduceSuggestedClassesBasedOnDependencyRuleViolation(classList, psiFile);
|
||||
classes = classList.toArray(PsiClass.EMPTY_ARRAY);
|
||||
CodeInsightUtil.sortIdenticalShortNamedMembers(classes, myReference);
|
||||
}
|
||||
|
||||
PsiClass[] array = classList.toArray(PsiClass.EMPTY_ARRAY);
|
||||
CodeInsightUtil.sortIdenticalShortNamedMembers(array, myReference);
|
||||
return array;
|
||||
return new CalcInfo(classes, extensionsAllowToChangeFileSilently, myInContent);
|
||||
}
|
||||
|
||||
public static boolean qualifiedNameAllowsAutoImport(@NotNull PsiFile placeFile, @NotNull PsiClass aClass) {
|
||||
|
||||
Reference in New Issue
Block a user