Search in sources :

Example 6 with PsiClassStub

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;
}
Also used : StubTree(com.intellij.psi.stubs.StubTree) PsiClass(com.intellij.psi.PsiClass) PsiClassStub(com.intellij.psi.impl.java.stubs.PsiClassStub)

Example 7 with PsiClassStub

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;
}
Also used : PsiClassStub(com.intellij.psi.impl.java.stubs.PsiClassStub)

Example 8 with PsiClassStub

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();
    }
}
Also used : IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiClassStub(com.intellij.psi.impl.java.stubs.PsiClassStub) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PsiClassStub

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;
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) PsiClassStub(com.intellij.psi.impl.java.stubs.PsiClassStub) StubBasedPsiElementBase(com.intellij.extapi.psi.StubBasedPsiElementBase) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with PsiClassStub

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();
}
Also used : ASTNode(com.intellij.lang.ASTNode) IStubElementType(com.intellij.psi.stubs.IStubElementType) PsiClassStub(com.intellij.psi.impl.java.stubs.PsiClassStub)

Aggregations

PsiClassStub (com.intellij.psi.impl.java.stubs.PsiClassStub)12 StubElement (com.intellij.psi.stubs.StubElement)4 ASTNode (com.intellij.lang.ASTNode)3 Nullable (org.jetbrains.annotations.Nullable)3 StubBasedPsiElementBase (com.intellij.extapi.psi.StubBasedPsiElementBase)1 PsiClass (com.intellij.psi.PsiClass)1 PsiClassInitializerStub (com.intellij.psi.impl.java.stubs.PsiClassInitializerStub)1 PsiMethodStub (com.intellij.psi.impl.java.stubs.PsiMethodStub)1 IStubElementType (com.intellij.psi.stubs.IStubElementType)1 PsiFileStub (com.intellij.psi.stubs.PsiFileStub)1 StubTree (com.intellij.psi.stubs.StubTree)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 NotNull (org.jetbrains.annotations.NotNull)1