Search in sources :

Example 1 with ObjectStubTree

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

the class FileDescriptionCachedValueProvider method _computeFileElement.

@Nullable
private DomFileElementImpl<T> _computeFileElement(final boolean fireEvents, @NotNull final XmlFileHeader rootTagName, @Nullable StringBuilder sb) {
    if (sb != null) {
        sb.append(rootTagName).append("\n");
    }
    if (!myXmlFile.isValid()) {
        return null;
    }
    if (sb != null) {
        sb.append("File is valid\n");
    }
    if (!(myXmlFile.getFileType() instanceof DomSupportEnabled)) {
        return null;
    }
    if (sb != null) {
        sb.append("File is of dom file type\n");
    }
    final DomFileDescription<T> description = findFileDescription(rootTagName, sb);
    final DomFileElementImpl oldValue = getLastValue();
    if (sb != null) {
        sb.append("last " + oldValue + "\n");
    }
    final List<DomEvent> events = fireEvents ? new SmartList<>() : Collections.<DomEvent>emptyList();
    if (oldValue != null) {
        if (fireEvents) {
            events.add(new DomEvent(oldValue, false));
        }
    }
    if (description == null) {
        return null;
    }
    final Class<T> rootElementClass = description.getRootElementClass();
    final XmlName xmlName = DomImplUtil.createXmlName(description.getRootTagName(), rootElementClass, null);
    assert xmlName != null;
    final EvaluatedXmlNameImpl rootTagName1 = EvaluatedXmlNameImpl.createEvaluatedXmlName(xmlName, xmlName.getNamespaceKey(), false);
    VirtualFile file = myXmlFile.getVirtualFile();
    FileStub stub = null;
    if (description.hasStubs() && file instanceof VirtualFileWithId && !isFileParsed()) {
        ApplicationManager.getApplication().assertReadAccessAllowed();
        if (!XmlUtil.isStubBuilding()) {
            ObjectStubTree stubTree = StubTreeLoader.getInstance().readOrBuild(myXmlFile.getProject(), file, myXmlFile);
            if (stubTree != null) {
                stub = (FileStub) stubTree.getRoot();
            }
        }
    }
    DomFileElementImpl<T> result = new DomFileElementImpl<>(myXmlFile, rootElementClass, rootTagName1, myDomManager, description, stub);
    if (sb != null) {
        sb.append("success " + result + "\n");
    }
    if (fireEvents) {
        events.add(new DomEvent(result, true));
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileStub(com.intellij.util.xml.stubs.FileStub) DomSupportEnabled(com.intellij.ide.highlighter.DomSupportEnabled) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) DomEvent(com.intellij.util.xml.events.DomEvent) ObjectStubTree(com.intellij.psi.stubs.ObjectStubTree) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ObjectStubTree

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

the class DomStubTest method getRootStub.

public static ElementStub getRootStub(@TestDataFile String filePath, JavaCodeInsightTestFixture fixture) {
    PsiFile psiFile = fixture.configureByFile(filePath);
    StubTreeLoader loader = StubTreeLoader.getInstance();
    VirtualFile file = psiFile.getVirtualFile();
    assertTrue(loader.canHaveStub(file));
    ObjectStubTree stubTree = loader.readFromVFile(fixture.getProject(), file);
    assertNotNull(stubTree);
    ElementStub root = (ElementStub) stubTree.getRoot();
    assertNotNull(root);
    return root;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StubTreeLoader(com.intellij.psi.stubs.StubTreeLoader) PsiFile(com.intellij.psi.PsiFile) ObjectStubTree(com.intellij.psi.stubs.ObjectStubTree)

Example 3 with ObjectStubTree

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

the class DomStubTest method prepareFile.

protected XmlFile prepareFile(String path) {
    VirtualFile virtualFile = myFixture.copyFileToProject(path);
    assertNotNull(virtualFile);
    XmlFile file = (XmlFile) ((PsiManagerEx) getPsiManager()).getFileManager().findFile(virtualFile);
    assertFalse(file.getNode().isParsed());
    ObjectStubTree tree = StubTreeLoader.getInstance().readOrBuild(getProject(), virtualFile, file);
    assertNotNull("Can't build stubs for " + path, tree);
    ((PsiManagerImpl) getPsiManager()).cleanupForNextTest();
    file = (XmlFile) getPsiManager().findFile(virtualFile);
    assertNotNull(file);
    return file;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) ObjectStubTree(com.intellij.psi.stubs.ObjectStubTree)

Example 4 with ObjectStubTree

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

the class DomStubBuilderTest method testNullTag.

public void testNullTag() throws Exception {
    VirtualFile virtualFile = myFixture.copyFileToProject("nullTag.xml");
    assertNotNull(virtualFile);
    PsiFile psiFile = ((PsiManagerEx) getPsiManager()).getFileManager().findFile(virtualFile);
    StubTreeLoader loader = StubTreeLoader.getInstance();
    VirtualFile file = psiFile.getVirtualFile();
    assertTrue(loader.canHaveStub(file));
    ObjectStubTree stubTree = loader.readFromVFile(getProject(), file);
    // no stubs for invalid XML
    assertNull(stubTree);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StubTreeLoader(com.intellij.psi.stubs.StubTreeLoader) PsiFile(com.intellij.psi.PsiFile) ObjectStubTree(com.intellij.psi.stubs.ObjectStubTree)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ObjectStubTree (com.intellij.psi.stubs.ObjectStubTree)4 PsiFile (com.intellij.psi.PsiFile)2 StubTreeLoader (com.intellij.psi.stubs.StubTreeLoader)2 DomSupportEnabled (com.intellij.ide.highlighter.DomSupportEnabled)1 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)1 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)1 PsiManagerImpl (com.intellij.psi.impl.PsiManagerImpl)1 XmlFile (com.intellij.psi.xml.XmlFile)1 DomEvent (com.intellij.util.xml.events.DomEvent)1 FileStub (com.intellij.util.xml.stubs.FileStub)1 Nullable (org.jetbrains.annotations.Nullable)1