Search in sources :

Example 1 with PsiClassReferenceListStub

use of com.intellij.psi.impl.java.stubs.PsiClassReferenceListStub in project intellij-community by JetBrains.

the class PsiClassImplUtil method isInReferenceList.

static boolean isInReferenceList(@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 = names[i];
                int typeParam = name.indexOf('<');
                if (typeParam != -1) {
                    name = name.substring(0, typeParam);
                }
                // baseName=="ArrayList" classStub.getReferenceNames()[i]=="java.util.ArrayList"
                if (name.endsWith(baseName)) {
                    PsiClassType[] referencedTypes = classStub.getReferencedTypes();
                    PsiClass resolved = referencedTypes[i].resolve();
                    if (manager.areElementsEquivalent(baseClass, resolved))
                        return true;
                }
            }
            return false;
        }
        if (stub != null) {
            // groovy etc
            for (PsiClassType type : list.getReferencedTypes()) {
                if (Comparing.equal(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 (Comparing.equal(type.getClassName(), baseName) && manager.areElementsEquivalent(baseClass, type.resolve())) {
            return true;
        }
    }
    return false;
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) PsiClassReferenceListStub(com.intellij.psi.impl.java.stubs.PsiClassReferenceListStub) ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint)

Example 2 with PsiClassReferenceListStub

use of com.intellij.psi.impl.java.stubs.PsiClassReferenceListStub in project intellij-community by JetBrains.

the class PsiReferenceListImpl method getReferencedTypes.

@Override
@NotNull
public PsiClassType[] getReferencedTypes() {
    PsiClassReferenceListStub stub = getGreenStub();
    if (stub != null) {
        return stub.getReferencedTypes();
    }
    PsiJavaCodeReferenceElement[] refs = getReferenceElements();
    PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
    PsiClassType[] types = new PsiClassType[refs.length];
    for (int i = 0; i < types.length; i++) {
        types[i] = factory.createType(refs[i]);
    }
    return types;
}
Also used : PsiClassReferenceListStub(com.intellij.psi.impl.java.stubs.PsiClassReferenceListStub) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiClassReferenceListStub (com.intellij.psi.impl.java.stubs.PsiClassReferenceListStub)2 ElementClassHint (com.intellij.psi.scope.ElementClassHint)1 NameHint (com.intellij.psi.scope.NameHint)1 StubElement (com.intellij.psi.stubs.StubElement)1 NotNull (org.jetbrains.annotations.NotNull)1