Search in sources :

Example 11 with StubElement

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

the class TreeUtil method bindStubsToTree.

public static void bindStubsToTree(@NotNull PsiFileImpl file, @NotNull StubTree stubTree, @NotNull FileElement tree) throws StubBindingException {
    final ListIterator<StubElement<?>> stubs = stubTree.getPlainList().listIterator();
    // skip file root stub
    stubs.next();
    final IStubFileElementType type = file.getElementTypeForStubBuilder();
    assert type != null;
    final StubBuilder builder = type.getBuilder();
    tree.acceptTree(new RecursiveTreeElementWalkingVisitor() {

        @Override
        protected void visitNode(TreeElement node) {
            CompositeElement parent = node.getTreeParent();
            if (parent != null && builder.skipChildProcessingWhenBuildingStubs(parent, node)) {
                return;
            }
            IElementType type = node.getElementType();
            if (type instanceof IStubElementType && ((IStubElementType) type).shouldCreateStub(node)) {
                final StubElement stub = stubs.hasNext() ? stubs.next() : null;
                if (stub == null || stub.getStubType() != type) {
                    throw new StubBindingException("stub:" + stub + ", AST:" + type);
                }
                StubBasedPsiElementBase psi = (StubBasedPsiElementBase) node.getPsi();
                //noinspection unchecked
                ((StubBase) stub).setPsi(psi);
                psi.setStubIndex(stubs.previousIndex());
            }
            super.visitNode(node);
        }
    });
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) StubElement(com.intellij.psi.stubs.StubElement) IStubElementType(com.intellij.psi.stubs.IStubElementType) StubBuilder(com.intellij.psi.StubBuilder) StubBasedPsiElementBase(com.intellij.extapi.psi.StubBasedPsiElementBase)

Example 12 with StubElement

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

the class TypeInfo method applyAnnotations.

@NotNull
public TypeInfo applyAnnotations(@NotNull StubBase<?> owner) {
    PsiModifierListStub modifierList = (PsiModifierListStub) owner.findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
    if (modifierList == null)
        return this;
    List<PsiAnnotationStub> annotationStubs = null;
    for (StubElement child : modifierList.getChildrenStubs()) {
        if (!(child instanceof PsiAnnotationStub))
            continue;
        PsiAnnotationStub annotationStub = (PsiAnnotationStub) child;
        if (PsiImplUtil.isTypeAnnotation(annotationStub.getPsiElement())) {
            if (annotationStubs == null)
                annotationStubs = new SmartList<>();
            annotationStubs.add(annotationStub);
        }
    }
    PsiAnnotationStub[] stubArray = PsiAnnotationStub.EMPTY_ARRAY;
    if (annotationStubs != null)
        stubArray = annotationStubs.toArray(new PsiAnnotationStub[annotationStubs.size()]);
    return new TypeInfo(text, arrayCount, isEllipsis, stubArray);
}
Also used : PsiAnnotationStub(com.intellij.psi.impl.java.stubs.PsiAnnotationStub) PsiModifierListStub(com.intellij.psi.impl.java.stubs.PsiModifierListStub) StubElement(com.intellij.psi.stubs.StubElement) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with StubElement

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

the class GroovyFileImpl method getPackageDefinition.

@Override
public GrPackageDefinition getPackageDefinition() {
    final StubElement<?> stub = getStub();
    if (stub != null) {
        for (StubElement element : stub.getChildrenStubs()) {
            if (element instanceof GrPackageDefinitionStub)
                return (GrPackageDefinition) element.getPsi();
        }
        return null;
    }
    ASTNode node = calcTreeElement().findChildByType(GroovyElementTypes.PACKAGE_DEFINITION);
    return node != null ? (GrPackageDefinition) node.getPsi() : null;
}
Also used : GrPackageDefinitionStub(org.jetbrains.plugins.groovy.lang.psi.stubs.GrPackageDefinitionStub) ASTNode(com.intellij.lang.ASTNode) StubElement(com.intellij.psi.stubs.StubElement)

Example 14 with StubElement

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

the class GrTraitUtil method doCollectCompiledTraitMethods.

private static void doCollectCompiledTraitMethods(final ClsClassImpl trait, final Collection<PsiMethod> result) {
    for (PsiMethod method : trait.getMethods()) {
        if (AnnotationUtil.isAnnotated(method, GROOVY_TRAIT_IMPLEMENTED, false)) {
            result.add(method);
        }
    }
    VirtualFile traitFile = trait.getContainingFile().getVirtualFile();
    if (traitFile == null)
        return;
    VirtualFile helperFile = traitFile.getParent().findChild(trait.getName() + GroovyTraitMethodsFileIndex.HELPER_SUFFIX);
    if (helperFile == null)
        return;
    int key = FileBasedIndex.getFileId(helperFile);
    List<PsiJavaFileStub> values = FileBasedIndex.getInstance().getValues(GroovyTraitMethodsFileIndex.INDEX_ID, key, trait.getResolveScope());
    values.forEach(root -> ((PsiJavaFileStubImpl) root).setPsi((PsiJavaFile) trait.getContainingFile()));
    values.stream().map(root -> root.getChildrenStubs().get(0).getChildrenStubs()).<StubElement>flatMap(Collection::stream).filter(stub -> stub instanceof PsiMethodStub).forEach(stub -> result.add(createTraitMethodFromCompiledHelperMethod(((PsiMethodStub) stub).getPsi(), trait)));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) ABSTRACT(com.intellij.psi.PsiModifier.ABSTRACT) ContainerUtil(com.intellij.util.containers.ContainerUtil) GrLightField(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) GrAnnotationUtil(org.jetbrains.plugins.groovy.lang.psi.impl.GrAnnotationUtil) Map(java.util.Map) InheritanceUtil(com.intellij.psi.util.InheritanceUtil) Logger(com.intellij.openapi.diagnostic.Logger) GROOVY_TRAIT(org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_TRAIT) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) ClsClassImpl(com.intellij.psi.impl.compiled.ClsClassImpl) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiJavaFileStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl) GROOVY_TRAIT_IMPLEMENTED(org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_TRAIT_IMPLEMENTED) Collection(java.util.Collection) TraitFieldDescriptor(org.jetbrains.plugins.groovy.lang.resolve.GroovyTraitFieldsFileIndex.TraitFieldDescriptor) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) GroovyTraitFieldsFileIndex(org.jetbrains.plugins.groovy.lang.resolve.GroovyTraitFieldsFileIndex) List(java.util.List) GroovyTraitMethodsFileIndex(org.jetbrains.plugins.groovy.lang.resolve.GroovyTraitMethodsFileIndex) AnnotationUtil(com.intellij.codeInsight.AnnotationUtil) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) com.intellij.psi(com.intellij.psi) StubElement(com.intellij.psi.stubs.StubElement) NotNull(org.jetbrains.annotations.NotNull) GrModifierFlags(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierFlags) Ref(com.intellij.openapi.util.Ref) PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) Collection(java.util.Collection) StubElement(com.intellij.psi.stubs.StubElement) PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub)

Example 15 with StubElement

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

the class GrStubIndexer method processClassDecl.

@Nullable
private static ClassDecl processClassDecl(GrTypeDefinitionStub classStub, Set<String> namesCache, boolean inner) {
    ArrayList<String> superList = new ArrayList<>();
    ArrayList<Decl> innerList = new ArrayList<>();
    if (classStub.isAnonymous()) {
        String name = classStub.getBaseClassName();
        if (name != null) {
            superList.add(id(name, true, namesCache));
        }
    }
    for (StubElement el : classStub.getChildrenStubs()) {
        if (el instanceof GrReferenceListStub) {
            GrReferenceListStub refList = (GrReferenceListStub) el;
            if (el.getStubType() == GroovyElementTypes.IMPLEMENTS_CLAUSE || el.getStubType() == GroovyElementTypes.EXTENDS_CLAUSE) {
                for (String extName : refList.getBaseClasses()) {
                    superList.add(id(extName, true, namesCache));
                }
            }
        }
        Decl member = processMember(el, namesCache);
        if (member != null) {
            innerList.add(member);
        }
    }
    int flags = translateFlags(classStub);
    if (inner && !superList.isEmpty()) {
        // 'extends' list resolves to classes from the current package first, and those can be in a language unknown to this hierarchy
        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 : ArrayList(java.util.ArrayList) StubElement(com.intellij.psi.stubs.StubElement) 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