Search in sources :

Example 1 with Stub

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

the class JavaStubIndexer method indexFile.

@Nullable
@Override
public Unit indexFile(@NotNull FileContent content) {
    Stub stubTree = StubTreeBuilder.buildStubTree(content);
    if (!(stubTree instanceof PsiJavaFileStub))
        return null;
    PsiJavaFileStub javaFileStub = (PsiJavaFileStub) stubTree;
    new StubTree(javaFileStub, false);
    List<ClassDecl> classList = new ArrayList<>();
    Set<String> usedNames = new HashSet<>();
    for (StubElement<?> el : javaFileStub.getChildrenStubs()) {
        if (el instanceof PsiClassStubImpl) {
            classList.add(processClassDecl((PsiClassStubImpl<?>) el, usedNames));
        }
    }
    List<IndexTree.Import> importList = new ArrayList<>();
    for (StubElement<?> el : javaFileStub.getChildrenStubs()) {
        if (el instanceof PsiImportListStub) {
            processImport((PsiImportListStub) el, importList, usedNames);
        }
    }
    ClassDecl[] classes = classList.isEmpty() ? ClassDecl.EMPTY_ARRAY : classList.toArray(new ClassDecl[classList.size()]);
    IndexTree.Import[] imports = importList.isEmpty() ? IndexTree.Import.EMPTY_ARRAY : importList.toArray(new IndexTree.Import[importList.size()]);
    byte type = javaFileStub.isCompiled() ? IndexTree.BYTECODE : IndexTree.JAVA;
    return new Unit(javaFileStub.getPackageName(), type, imports, classes);
}
Also used : PsiClassStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl) StubTree(com.intellij.psi.stubs.StubTree) ArrayList(java.util.ArrayList) Stub(com.intellij.psi.stubs.Stub) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Stub

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

the class DebugUtil method stubTreeToBuffer.

public static void stubTreeToBuffer(final Stub node, final Appendable buffer, final int indent) {
    StringUtil.repeatSymbol(buffer, ' ', indent);
    try {
        final ObjectStubSerializer stubType = node.getStubType();
        if (stubType != null) {
            buffer.append(stubType.toString()).append(':');
        }
        buffer.append(node.toString()).append('\n');
        @SuppressWarnings({ "unchecked" }) final List<? extends Stub> children = node.getChildrenStubs();
        for (final Stub child : children) {
            stubTreeToBuffer(child, buffer, indent + 2);
        }
    } catch (IOException e) {
        LOG.error(e);
    }
}
Also used : ObjectStubSerializer(com.intellij.psi.stubs.ObjectStubSerializer) Stub(com.intellij.psi.stubs.Stub) IOException(java.io.IOException)

Example 3 with Stub

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

the class GrStubIndexer method indexFile.

@Nullable
@Override
public Unit indexFile(@NotNull FileContent content) {
    if (!isNormalGroovyFile(((FileContentImpl) content).getPsiFileForPsiDependentIndex()))
        return null;
    Stub stubTree = StubTreeBuilder.buildStubTree(content);
    if (!(stubTree instanceof GrFileStub))
        return null;
    GrFileStub grFileStub = (GrFileStub) stubTree;
    new StubTree(grFileStub, false);
    String pid = "";
    ArrayList<ClassDecl> classList = new ArrayList<>();
    Set<String> usedNames = new HashSet<>();
    for (StubElement<?> el : grFileStub.getChildrenStubs()) {
        if (el instanceof GrPackageDefinitionStub) {
            GrPackageDefinitionStub packageStub = (GrPackageDefinitionStub) el;
            String pkgName = packageStub.getPackageName();
            if (pkgName != null) {
                pid = id(pkgName, false, null);
            }
        }
        if (el instanceof GrTypeDefinitionStub) {
            ClassDecl classDecl = processClassDecl((GrTypeDefinitionStub) el, usedNames, false);
            if (classDecl != null) {
                classList.add(classDecl);
            }
        }
    }
    ArrayList<Import> importList = new ArrayList<>();
    for (StubElement<?> el : grFileStub.getChildrenStubs()) {
        if (el instanceof GrImportStatementStub) {
            processImport((GrImportStatementStub) el, importList, usedNames);
        }
    }
    ClassDecl[] classes = classList.isEmpty() ? ClassDecl.EMPTY_ARRAY : classList.toArray(new ClassDecl[classList.size()]);
    Import[] imports = importList.isEmpty() ? Import.EMPTY_ARRAY : importList.toArray(new Import[importList.size()]);
    return new Unit(pid, IndexTree.GROOVY, imports, classes);
}
Also used : StubTree(com.intellij.psi.stubs.StubTree) ArrayList(java.util.ArrayList) Stub(com.intellij.psi.stubs.Stub) FileContentImpl(com.intellij.util.indexing.FileContentImpl) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Stub (com.intellij.psi.stubs.Stub)3 StubTree (com.intellij.psi.stubs.StubTree)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Nullable (org.jetbrains.annotations.Nullable)2 PsiClassStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl)1 ObjectStubSerializer (com.intellij.psi.stubs.ObjectStubSerializer)1 FileContentImpl (com.intellij.util.indexing.FileContentImpl)1 IOException (java.io.IOException)1