Search in sources :

Example 1 with JavaClassReferenceListElementType

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

the class PsiClassReferenceListStubImpl method getReferencedTypes.

@NotNull
@Override
public PsiClassType[] getReferencedTypes() {
    if (myTypes != null)
        return myTypes;
    if (myNames.length == 0) {
        myTypes = PsiClassType.EMPTY_ARRAY;
        return myTypes;
    }
    PsiClassType[] types = new PsiClassType[myNames.length];
    final boolean compiled = ((JavaClassReferenceListElementType) getStubType()).isCompiled(this);
    if (compiled) {
        for (int i = 0; i < types.length; i++) {
            types[i] = new PsiClassReferenceType(new ClsJavaCodeReferenceElementImpl(getPsi(), myNames[i]), null);
        }
    } else {
        final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
        int nullCount = 0;
        final PsiReferenceList psi = getPsi();
        for (int i = 0; i < types.length; i++) {
            try {
                final PsiJavaCodeReferenceElement ref = factory.createReferenceFromText(myNames[i], psi);
                ((PsiJavaCodeReferenceElementImpl) ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND);
                types[i] = factory.createType(ref);
            } catch (IncorrectOperationException e) {
                types[i] = null;
                nullCount++;
            }
        }
        if (nullCount > 0) {
            PsiClassType[] newTypes = new PsiClassType[types.length - nullCount];
            int cnt = 0;
            for (PsiClassType type : types) {
                if (type != null)
                    newTypes[cnt++] = type;
            }
            types = newTypes;
        }
    }
    myTypes = types;
    return types.clone();
}
Also used : ClsJavaCodeReferenceElementImpl(com.intellij.psi.impl.compiled.ClsJavaCodeReferenceElementImpl) JavaClassReferenceListElementType(com.intellij.psi.impl.java.stubs.JavaClassReferenceListElementType) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiClassReferenceType(com.intellij.psi.impl.source.PsiClassReferenceType) PsiJavaCodeReferenceElementImpl(com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ClsJavaCodeReferenceElementImpl (com.intellij.psi.impl.compiled.ClsJavaCodeReferenceElementImpl)1 JavaClassReferenceListElementType (com.intellij.psi.impl.java.stubs.JavaClassReferenceListElementType)1 PsiClassReferenceType (com.intellij.psi.impl.source.PsiClassReferenceType)1 PsiJavaCodeReferenceElementImpl (com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 NotNull (org.jetbrains.annotations.NotNull)1