Search in sources :

Example 6 with StubElement

use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.

the class PyTargetExpressionImpl method getContainingClass.

@Override
public PyClass getContainingClass() {
    final PyTargetExpressionStub stub = getStub();
    if (stub != null) {
        final StubElement parentStub = stub.getParentStub();
        if (parentStub instanceof PyClassStub) {
            return ((PyClassStub) parentStub).getPsi();
        }
        if (parentStub instanceof PyFunctionStub) {
            final StubElement functionParent = parentStub.getParentStub();
            if (functionParent instanceof PyClassStub) {
                return ((PyClassStub) functionParent).getPsi();
            }
        }
        return null;
    }
    final PsiElement parent = PsiTreeUtil.getParentOfType(this, PyFunction.class, PyClass.class);
    if (parent instanceof PyClass) {
        return (PyClass) parent;
    }
    if (parent instanceof PyFunction) {
        return ((PyFunction) parent).getContainingClass();
    }
    return null;
}
Also used : PyClassStub(com.jetbrains.python.psi.stubs.PyClassStub) PyTargetExpressionStub(com.jetbrains.python.psi.stubs.PyTargetExpressionStub) StubElement(com.intellij.psi.stubs.StubElement) PyFunctionStub(com.jetbrains.python.psi.stubs.PyFunctionStub) PsiElement(com.intellij.psi.PsiElement)

Example 7 with StubElement

use of com.intellij.psi.stubs.StubElement in project smali by JesusFreke.

the class SmaliStubBasedPsiElement method findStubOrPsiAncestorOfType.

@SuppressWarnings("unchecked")
@Nullable
protected <E extends PsiElement> E findStubOrPsiAncestorOfType(@NotNull Class<E> aClass) {
    T stub = getStub();
    if (stub != null) {
        StubElement parent = stub.getParentStub();
        while (parent != null) {
            PsiElement parentPsi = parent.getPsi();
            if (aClass.isInstance(parentPsi)) {
                return (E) parentPsi;
            }
            parent = parent.getParentStub();
        }
        return null;
    }
    PsiElement parent = getParent();
    while (parent != null) {
        if (aClass.isInstance(parent)) {
            return (E) parent;
        }
        parent = parent.getParent();
    }
    return null;
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with StubElement

use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.

the class JavaStubIndexer method processClassDecl.

@NotNull
private static ClassDecl processClassDecl(PsiClassStubImpl<?> classStub, Set<String> namesCache) {
    List<String> superList = new ArrayList<>();
    List<Decl> innerList = new ArrayList<>();
    if (classStub.isAnonymous()) {
        if (classStub.getBaseClassReferenceText() != null) {
            superList.add(id(classStub.getBaseClassReferenceText(), namesCache));
        }
    }
    for (StubElement el : classStub.getChildrenStubs()) {
        if (el instanceof PsiClassReferenceListStub) {
            PsiClassReferenceListStub refList = (PsiClassReferenceListStub) el;
            PsiReferenceList.Role role = refList.getRole();
            if (role == PsiReferenceList.Role.EXTENDS_LIST || role == PsiReferenceList.Role.IMPLEMENTS_LIST) {
                for (String extName : refList.getReferencedNames()) {
                    superList.add(id(extName, namesCache));
                }
            }
        }
        Decl member = processMember(el, namesCache);
        if (member != null) {
            innerList.add(member);
        }
    }
    int flags = translateFlags(classStub);
    if (classStub.isAnonymousInQualifiedNew()) {
        flags |= IndexTree.SUPERS_UNRESOLVED;
    }
    String[] supers = superList.isEmpty() ? ArrayUtil.EMPTY_STRING_ARRAY : ArrayUtil.toStringArray(superList);
    Decl[] inners = innerList.isEmpty() ? Decl.EMPTY_ARRAY : innerList.toArray(new Decl[innerList.size()]);
    return new ClassDecl(classStub.id, flags, classStub.getName(), supers, inners);
}
Also used : PsiReferenceList(com.intellij.psi.PsiReferenceList) ArrayList(java.util.ArrayList) StubElement(com.intellij.psi.stubs.StubElement) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with StubElement

use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.

the class ClassPresentationUtil method getFunctionalExpressionPresentation.

public static String getFunctionalExpressionPresentation(PsiFunctionalExpression functionalExpression, boolean qualified) {
    final StubElement stub = ((StubBasedPsiElementBase<?>) functionalExpression).getGreenStub();
    final String lambdaText = stub instanceof FunctionalExpressionStub ? ((FunctionalExpressionStub) stub).getPresentableText() : PsiExpressionTrimRenderer.render(functionalExpression);
    return PsiBundle.message("class.context.display", lambdaText, getContextName(functionalExpression, qualified));
}
Also used : FunctionalExpressionStub(com.intellij.psi.impl.java.stubs.FunctionalExpressionStub) StubElement(com.intellij.psi.stubs.StubElement) StubBasedPsiElementBase(com.intellij.extapi.psi.StubBasedPsiElementBase)

Example 10 with StubElement

use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.

the class PsiClassImpl method getContextStub.

@Nullable
private StubElement getContextStub() {
    PsiClassStub<?> stub = getStub();
    if (stub == null)
        return null;
    // if AST is not loaded, then we only can need context to resolve supertype references
    // this can be done by stubs unless there are local/anonymous classes referencing other local classes
    StubElement parent = stub.getParentStub();
    if (parent instanceof PsiClassInitializerStub || parent instanceof PsiMethodStub) {
        if (parent.getChildrenByType(JavaStubElementTypes.CLASS, PsiElement.ARRAY_FACTORY).length <= 1) {
            parent = parent.getParentStub();
        }
    }
    return parent instanceof PsiClassStub ? parent : null;
}
Also used : PsiClassInitializerStub(com.intellij.psi.impl.java.stubs.PsiClassInitializerStub) PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) StubElement(com.intellij.psi.stubs.StubElement) PsiClassStub(com.intellij.psi.impl.java.stubs.PsiClassStub) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StubElement (com.intellij.psi.stubs.StubElement)38 Nullable (org.jetbrains.annotations.Nullable)9 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)7 StubBasedPsiElement (com.intellij.psi.StubBasedPsiElement)4 PsiClassStub (com.intellij.psi.impl.java.stubs.PsiClassStub)4 StubTree (com.intellij.psi.stubs.StubTree)4 StubBasedPsiElementBase (com.intellij.extapi.psi.StubBasedPsiElementBase)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)3 PsiFileStub (com.intellij.psi.stubs.PsiFileStub)3 SmartList (com.intellij.util.SmartList)3 PyClassStub (com.jetbrains.python.psi.stubs.PyClassStub)3 GoFileStub (com.goide.stubs.GoFileStub)2 ASTNode (com.intellij.lang.ASTNode)2 FileASTNode (com.intellij.lang.FileASTNode)2 PsiFile (com.intellij.psi.PsiFile)2 StubBuilder (com.intellij.psi.StubBuilder)2 PsiMethodStub (com.intellij.psi.impl.java.stubs.PsiMethodStub)2 IElementType (com.intellij.psi.tree.IElementType)2