use of com.intellij.psi.impl.java.stubs.PsiClassStub in project intellij-community by JetBrains.
the class JavaCompilerElementRetriever method retrieveMatchedClasses.
private static List<PsiClass> retrieveMatchedClasses(PsiFileWithStubSupport psiFile, Collection<InternalClassMatcher> matchers) {
final List<PsiClass> result = new ArrayList<>(matchers.size());
StubTree tree = psiFile.getStubTree();
boolean foreign = tree == null;
if (foreign) {
tree = ((PsiFileImpl) psiFile).calcStubTree();
}
for (StubElement<?> element : tree.getPlainList()) {
if (element instanceof PsiClassStub && match((PsiClassStub) element, matchers)) {
result.add(((StubBase<PsiClass>) element).getPsi());
}
}
return result;
}
use of com.intellij.psi.impl.java.stubs.PsiClassStub in project intellij-community by JetBrains.
the class PsiAnonymousClassImpl method isInQualifiedNew.
@Override
public boolean isInQualifiedNew() {
final PsiClassStub stub = getGreenStub();
if (stub != null) {
return stub.isAnonymousInQualifiedNew();
}
final PsiElement parent = getParent();
return parent instanceof PsiNewExpression && ((PsiNewExpression) parent).getQualifier() != null;
}
use of com.intellij.psi.impl.java.stubs.PsiClassStub in project intellij-community by JetBrains.
the class PsiAnonymousClassImpl method getBaseClassType.
@Override
@NotNull
public PsiClassType getBaseClassType() {
final PsiClassStub stub = getGreenStub();
if (stub == null) {
myCachedBaseType = null;
return getTypeByTree();
}
PsiClassType type = SoftReference.dereference(myCachedBaseType);
if (type != null)
return type;
if (!isInQualifiedNew() && !isDiamond(stub)) {
final String refText = stub.getBaseClassReferenceText();
assert refText != null : stub;
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
final PsiElement context = calcBasesResolveContext(PsiNameHelper.getShortClassName(refText), getExtendsList());
try {
final PsiJavaCodeReferenceElement ref = factory.createReferenceFromText(refText, context);
((PsiJavaCodeReferenceElementImpl) ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND);
type = factory.createType(ref);
} catch (IncorrectOperationException e) {
type = PsiType.getJavaLangObject(getManager(), getResolveScope());
}
myCachedBaseType = new SoftReference<>(type);
return type;
} else {
return getTypeByTree();
}
}
use of com.intellij.psi.impl.java.stubs.PsiClassStub in project intellij-community by JetBrains.
the class PsiClassImpl method calcBasesResolveContext.
@Nullable
private static PsiElement calcBasesResolveContext(@NotNull PsiElement scope, String baseClassName, boolean isInitialClass, final PsiElement defaultResolveContext) {
final StubElement stub = scope instanceof StubBasedPsiElementBase ? ((StubBasedPsiElementBase<?>) scope).getStub() : null;
if (stub == null || stub instanceof PsiClassStub && ((PsiClassStub) stub).isAnonymousInQualifiedNew()) {
return scope.getParent();
}
if (scope instanceof PsiClass) {
if (!isAnonymousOrLocal((PsiClass) scope)) {
return isInitialClass ? defaultResolveContext : scope;
}
if (!isInitialClass) {
if (((PsiClass) scope).findInnerClassByName(baseClassName, true) != null)
return scope;
}
}
final StubElement parentStub = stub.getParentStub();
PsiElement psi = parentStub.getPsi();
if (!(psi instanceof StubBasedPsiElementBase)) {
LOG.error(stub + " parent is " + parentStub);
return null;
}
if (hasChildClassStub(parentStub, baseClassName, scope)) {
return scope.getParent();
}
if (psi instanceof PsiClass || psi instanceof PsiFunctionalExpression) {
return calcBasesResolveContext(psi, baseClassName, false, defaultResolveContext);
}
if (psi instanceof PsiMember) {
PsiClass containingClass = ((PsiMember) psi).getContainingClass();
return containingClass != null ? calcBasesResolveContext(containingClass, baseClassName, false, defaultResolveContext) : psi;
}
LOG.error(parentStub);
return psi;
}
use of com.intellij.psi.impl.java.stubs.PsiClassStub in project intellij-community by JetBrains.
the class PsiClassImpl method getScope.
@Override
public PsiElement getScope() {
final PsiClassStub stub = getStub();
if (stub != null) {
return stub.getParentStub().getPsi();
}
ASTNode treeElement = getNode();
ASTNode parent = treeElement.getTreeParent();
while (parent != null) {
if (parent.getElementType() instanceof IStubElementType) {
return parent.getPsi();
}
parent = parent.getTreeParent();
}
return getContainingFile();
}
Aggregations