Search in sources :

Example 36 with StubElement

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

the class PyFileImpl method hasImportFromFuture.

@Override
public boolean hasImportFromFuture(FutureFeature feature) {
    final StubElement stub = getStub();
    if (stub instanceof PyFileStub) {
        return ((PyFileStub) stub).getFutureFeatures().get(feature.ordinal());
    }
    Boolean enabled = myFutureFeatures.get(feature);
    if (enabled == null) {
        enabled = calculateImportFromFuture(feature);
        myFutureFeatures.put(feature, enabled);
    // NOTE: ^^^ not synchronized. if two threads will try to modify this, both can only be expected to set the same value.
    }
    return enabled;
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) PyFileStub(com.jetbrains.python.psi.stubs.PyFileStub)

Example 37 with StubElement

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

the class PyStubsTest method testRenamingUpdatesTheStub.

public void testRenamingUpdatesTheStub() {
    final PyFile file = getTestFile("LoadingTreeRetainsKnownPsiElement.py");
    final List<PyClass> classes = file.getTopLevelClasses();
    assertEquals(1, classes.size());
    final PyClass pyClass = classes.get(0);
    assertEquals("SomeClass", pyClass.getName());
    // Ensure we haven't loaded the tree yet.
    final PyFileImpl fileImpl = (PyFileImpl) file;
    assertNull(fileImpl.getTreeElement());
    // Load the tree
    final PsiElement[] children = file.getChildren();
    assertNotNull(fileImpl.getTreeElement());
    assertEquals(1, children.length);
    assertSame(pyClass, children[0]);
    new WriteCommandAction(myFixture.getProject(), fileImpl) {

        @Override
        protected void run(@NotNull final Result result) throws Throwable {
            pyClass.setName("RenamedClass");
            assertEquals("RenamedClass", pyClass.getName());
        }
    }.execute();
    StubElement fileStub = fileImpl.getStub();
    assertNull("There should be no stub if file holds tree element", fileStub);
    new WriteCommandAction(myFixture.getProject(), fileImpl) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            ((SingleRootFileViewProvider) fileImpl.getViewProvider()).onContentReload();
        }
    }.execute();
    // Test unload succeeded.
    assertNull(fileImpl.getTreeElement());
    assertEquals("RenamedClass", fileImpl.getTopLevelClasses().get(0).getName());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PyFileImpl(com.jetbrains.python.psi.impl.PyFileImpl) StubElement(com.intellij.psi.stubs.StubElement) Result(com.intellij.openapi.application.Result)

Example 38 with StubElement

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

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