@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(), StringRef.toString(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++) { PsiElement context = psi; if (getParentStub() instanceof PsiClassStub) { context = ((PsiClassImpl)getParentStub().getPsi()).calcBasesResolveContext(PsiNameHelper.getShortClassName(StringRef.toString(myNames[i])), psi); } try { final PsiJavaCodeReferenceElement ref = factory.createReferenceFromText(StringRef.toString(myNames[i]), context); ((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; }
@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(); }