boolean (@Nullable PsiReferenceList list, @NotNull PsiClass baseClass, @Nullable String baseName, @NotNull PsiManager manager) { if (list == null) return false; if (list instanceof StubBasedPsiElement) { StubElement<?> stub = ((StubBasedPsiElement<?>)list).getStub(); if (stub instanceof PsiClassReferenceListStub && baseName != null) { // classStub.getReferencedNames() is cheaper than getReferencedTypes() PsiClassReferenceListStub classStub = (PsiClassReferenceListStub)stub; String[] names = classStub.getReferencedNames(); for (int i = 0; i < names.length; i++) { String name = PsiNameHelper.getShortClassName(names[i]); // baseName=="ArrayList" classStub.getReferenceNames()[i]=="java.util.ArrayList" if (name.endsWith(baseName)) { PsiClassType[] referencedTypes = classStub.getReferencedTypes(); PsiClassType type = i >= referencedTypes.length ? null : referencedTypes[i]; PsiClass resolved = type == null ? null : type.resolve(); if (manager.areElementsEquivalent(baseClass, resolved)) return true; } } return false; } if (stub != null) { // groovy etc for (PsiClassType type : list.getReferencedTypes()) { if (Objects.equals(type.getClassName(), baseName) && manager.areElementsEquivalent(baseClass, type.resolve())) { return true; } } return false; } } if (list.getLanguage() == JavaLanguage.INSTANCE) { // groovy doesn't have list.getReferenceElements() for (PsiJavaCodeReferenceElement referenceElement : list.getReferenceElements()) { if (Comparing.strEqual(baseName, referenceElement.getReferenceName()) && manager.areElementsEquivalent(baseClass, referenceElement.resolve())) { return true; } } return false; } for (PsiClassType type : list.getReferencedTypes()) { if (Objects.equals(type.getClassName(), baseName) && manager.areElementsEquivalent(baseClass, type.resolve())) { return true; } } return false; }