Search in sources :

Example 6 with StubTree

use of com.intellij.psi.stubs.StubTree in project intellij-plugins by JetBrains.

the class FlexStyleIndex method getIndexer.

@NotNull
@Override
public DataIndexer<String, Set<FlexStyleIndexInfo>, FileContent> getIndexer() {
    return new DataIndexer<String, Set<FlexStyleIndexInfo>, FileContent>() {

        @Override
        @NotNull
        public Map<String, Set<FlexStyleIndexInfo>> map(@NotNull FileContent inputData) {
            final THashMap<String, Set<FlexStyleIndexInfo>> map = new THashMap<>();
            if (JavaScriptSupportLoader.isFlexMxmFile(inputData.getFileName())) {
                PsiFile file = inputData.getPsiFile();
                VirtualFile virtualFile = inputData.getFile();
                if (file instanceof XmlFile) {
                    indexMxmlFile((XmlFile) file, virtualFile, map);
                }
            } else {
                StubTree tree = JSPackageIndex.getStubTree(inputData);
                if (tree != null) {
                    for (StubElement e : tree.getPlainList()) {
                        if (e instanceof JSClassStub) {
                            final PsiElement psiElement = e.getPsi();
                            if (psiElement instanceof JSClass) {
                                final String qName = ((JSClass) psiElement).getQualifiedName();
                                indexAttributes(psiElement, qName, true, map);
                            }
                        } else if (e instanceof PsiFileStub) {
                            PsiElement psiElement = e.getPsi();
                            if (psiElement instanceof JSFile) {
                                String name = ((JSFile) psiElement).getName();
                                indexAttributes(psiElement, name, false, map);
                            }
                        }
                    }
                }
            }
            return map;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) XmlFile(com.intellij.psi.xml.XmlFile) StubTree(com.intellij.psi.stubs.StubTree) StubElement(com.intellij.psi.stubs.StubElement) NotNull(org.jetbrains.annotations.NotNull) THashMap(gnu.trove.THashMap) JSClassStub(com.intellij.lang.javascript.psi.stubs.JSClassStub) PsiFileStub(com.intellij.psi.stubs.PsiFileStub) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with StubTree

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

Example 8 with StubTree

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

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

the class SmartPsiElementPointersTest method assertTreeLoaded.

private static void assertTreeLoaded(PsiFileImpl file, boolean loaded) {
    FileElement treeElement = file.getTreeElement();
    assertEquals(loaded, treeElement != null);
    StubTree stubTree = file.getStubTree();
    assertEquals(loaded, stubTree == null);
}
Also used : StubTree(com.intellij.psi.stubs.StubTree) FileElement(com.intellij.psi.impl.source.tree.FileElement)

Example 10 with StubTree

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

the class SmartPsiElementPointersTest method testNonAnchoredStubbedElement.

public void testNonAnchoredStubbedElement() {
    PsiFile file = configureByText(JavaFileType.INSTANCE, "class Foo { { @NotNull String foo; } }");
    StubTree stubTree = ((PsiFileImpl) file).getStubTree();
    assertNotNull(stubTree);
    PsiElement anno = stubTree.getPlainList().stream().map(StubElement::getPsi).filter(psiElement -> psiElement instanceof PsiAnnotation).findFirst().get();
    SmartPsiElementPointer<PsiElement> pointer = createPointer(anno);
    assertNotNull(((PsiFileImpl) file).getStubTree());
    stubTree = null;
    anno = null;
    PlatformTestUtil.tryGcSoftlyReachableObjects();
    assertNull(((SmartPointerEx) pointer).getCachedElement());
    insertString(file.getViewProvider().getDocument(), 0, " ");
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    assertNotNull(pointer.getElement());
}
Also used : StubTree(com.intellij.psi.stubs.StubTree) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl)

Aggregations

StubTree (com.intellij.psi.stubs.StubTree)12 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)6 StubElement (com.intellij.psi.stubs.StubElement)4 Nullable (org.jetbrains.annotations.Nullable)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Stub (com.intellij.psi.stubs.Stub)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 NotNull (org.jetbrains.annotations.NotNull)2 JSFile (com.intellij.lang.javascript.psi.JSFile)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 JSClassStub (com.intellij.lang.javascript.psi.stubs.JSClassStub)1 Attachment (com.intellij.openapi.diagnostic.Attachment)1 Module (com.intellij.openapi.module.Module)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiFunctionalExpression (com.intellij.psi.PsiFunctionalExpression)1 PsiClassStub (com.intellij.psi.impl.java.stubs.PsiClassStub)1 PsiClassStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl)1