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;
}
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;
}
Aggregations