Search in sources :

Example 16 with StubElement

use of com.intellij.psi.stubs.StubElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPsiTreeUtil method getStubChildrenOfTypeAsList.

@NotNull
public static <T extends PsiElement> List<T> getStubChildrenOfTypeAsList(@Nullable PsiElement element, @NotNull Class<T> aClass) {
    if (element == null)
        return Collections.emptyList();
    StubElement<?> stub = element instanceof StubBasedPsiElement ? ((StubBasedPsiElement) element).getStub() : null;
    if (stub == null) {
        return getChildrenOfTypeAsList(element, aClass);
    }
    List<T> result = new SmartList<T>();
    for (StubElement childStub : stub.getChildrenStubs()) {
        PsiElement child = childStub.getPsi();
        if (aClass.isInstance(child)) {
            //noinspection unchecked
            result.add((T) child);
        }
    }
    return result;
}
Also used : StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) SmartList(com.intellij.util.SmartList) StubElement(com.intellij.psi.stubs.StubElement) StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with StubElement

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

the class AnchorRepository method restoreFromStubIndex.

private static PsiElement restoreFromStubIndex(PsiFileWithStubSupport fileImpl, int index) {
    StubTree tree = fileImpl.getStubTree();
    if (tree == null) {
        if (fileImpl instanceof PsiFileImpl) {
            tree = ((PsiFileImpl) fileImpl).calcStubTree();
        } else {
            return null;
        }
    }
    List<StubElement<?>> list = tree.getPlainList();
    if (index >= list.size()) {
        return null;
    }
    return ((StubElement) list.get(index)).getPsi();
}
Also used : StubTree(com.intellij.psi.stubs.StubTree) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) StubElement(com.intellij.psi.stubs.StubElement)

Example 18 with StubElement

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

the class JavaMethodElementType method indexStub.

@Override
public void indexStub(@NotNull final PsiMethodStub stub, @NotNull final IndexSink sink) {
    final String name = stub.getName();
    if (name != null) {
        sink.occurrence(JavaStubIndexKeys.METHODS, name);
        if (RecordUtil.isStaticNonPrivateMember(stub)) {
            sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_NAMES, name);
            sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_TYPES, stub.getReturnTypeText(false).getShortTypeText());
        }
    }
    Set<String> methodTypeParams = getVisibleTypeParameters(stub);
    for (StubElement stubElement : stub.getChildrenStubs()) {
        if (stubElement instanceof PsiParameterListStub) {
            for (StubElement paramStub : ((PsiParameterListStub) stubElement).getChildrenStubs()) {
                if (paramStub instanceof PsiParameterStub) {
                    TypeInfo type = ((PsiParameterStub) paramStub).getType(false);
                    String typeName = PsiNameHelper.getShortClassName(type.text);
                    if (TypeConversionUtil.isPrimitive(typeName) || TypeConversionUtil.isPrimitiveWrapper(typeName))
                        continue;
                    sink.occurrence(JavaStubIndexKeys.METHOD_TYPES, typeName);
                    if (typeName.equals(type.text) && (type.arrayCount == 0 || type.arrayCount == 1 && type.isEllipsis) && methodTypeParams.contains(typeName)) {
                        sink.occurrence(JavaStubIndexKeys.METHOD_TYPES, TYPE_PARAMETER_PSEUDO_NAME);
                    }
                }
            }
            break;
        }
    }
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) TypeInfo(com.intellij.psi.impl.cache.TypeInfo)

Example 19 with StubElement

use of com.intellij.psi.stubs.StubElement 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 20 with StubElement

use of com.intellij.psi.stubs.StubElement 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)

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