Search in sources :

Example 1 with FileStub

use of com.intellij.util.xml.stubs.FileStub 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 FileStub

use of com.intellij.util.xml.stubs.FileStub in project intellij-community by JetBrains.

the class DomStubBuilder method buildStubTree.

@Override
public Stub buildStubTree(FileContent fileContent) {
    PsiFile psiFile = fileContent.getPsiFile();
    if (!(psiFile instanceof XmlFile))
        return null;
    Document document = FileDocumentManager.getInstance().getCachedDocument(fileContent.getFile());
    Project project = fileContent.getProject();
    if (project == null) {
        project = psiFile.getProject();
    }
    if (document != null) {
        PsiFile existingPsi = PsiDocumentManager.getInstance(project).getPsiFile(document);
        if (existingPsi instanceof XmlFile) {
            psiFile = existingPsi;
        }
    }
    XmlFile xmlFile = (XmlFile) psiFile;
    try {
        XmlUtil.BUILDING_DOM_STUBS.set(Boolean.TRUE);
        DomFileElement<? extends DomElement> fileElement = DomManager.getDomManager(project).getFileElement(xmlFile);
        if (fileElement == null || !fileElement.getFileDescription().hasStubs())
            return null;
        XmlFileHeader header = DomService.getInstance().getXmlFileHeader(xmlFile);
        if (header.getRootTagLocalName() == null) {
            LOG.error("null root tag for " + fileElement + " for " + fileContent.getFile());
        }
        FileStub fileStub = new FileStub(header);
        XmlTag rootTag = xmlFile.getRootTag();
        if (rootTag != null) {
            new DomStubBuilderVisitor(DomManagerImpl.getDomManager(project)).visitXmlElement(rootTag, fileStub, 0);
        }
        return fileStub;
    } finally {
        XmlUtil.BUILDING_DOM_STUBS.set(Boolean.FALSE);
        SemService.getSemService(project).clearCache();
    }
}
Also used : Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) FileStub(com.intellij.util.xml.stubs.FileStub) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

FileStub (com.intellij.util.xml.stubs.FileStub)2 DomSupportEnabled (com.intellij.ide.highlighter.DomSupportEnabled)1 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)1 PsiFile (com.intellij.psi.PsiFile)1 ObjectStubTree (com.intellij.psi.stubs.ObjectStubTree)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 DomEvent (com.intellij.util.xml.events.DomEvent)1 Nullable (org.jetbrains.annotations.Nullable)1