Search in sources :

Example 11 with PsiClassStub

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

the class PsiClassImpl method getContainingClass.

@Override
@Nullable
public PsiClass getContainingClass() {
    final PsiClassStub stub = getGreenStub();
    if (stub != null) {
        StubElement parent = stub.getParentStub();
        return parent instanceof PsiClassStub ? ((PsiClassStub<?>) parent).getPsi() : null;
    }
    PsiElement parent = getParent();
    if (parent instanceof PsiClassLevelDeclarationStatement) {
        return PsiTreeUtil.getParentOfType(this, PsiSyntheticClass.class);
    }
    return parent instanceof PsiClass ? (PsiClass) parent : null;
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) PsiClassStub(com.intellij.psi.impl.java.stubs.PsiClassStub) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with PsiClassStub

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

the class PsiClassImpl method isAnonymousOrLocal.

private static boolean isAnonymousOrLocal(PsiClass aClass) {
    if (aClass instanceof PsiAnonymousClass)
        return true;
    final PsiClassStub stub = ((PsiClassImpl) aClass).getGreenStub();
    if (stub != null) {
        final StubElement parentStub = stub.getParentStub();
        return !(parentStub instanceof PsiClassStub || parentStub instanceof PsiFileStub);
    }
    PsiElement parent = aClass.getParent();
    while (parent != null) {
        if (parent instanceof PsiMethod || parent instanceof PsiField || parent instanceof PsiClassInitializer)
            return true;
        if (parent instanceof PsiClass || parent instanceof PsiFile)
            return false;
        parent = parent.getParent();
    }
    return false;
}
Also used : PsiFileStub(com.intellij.psi.stubs.PsiFileStub) StubElement(com.intellij.psi.stubs.StubElement) 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