@NotNull private static XmlFileHeader calcXmlFileHeader(final XmlFile file) { if (file instanceof PsiFileEx && ((PsiFileEx)file).isContentsLoaded() && file.getNode().isParsed()) { return computeHeaderByPsi(file); } if (!XmlUtil.isStubBuilding() && file.getFileType() == XmlFileType.INSTANCE) { VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile instanceof VirtualFileWithId) { ObjectStubTree tree = StubTreeLoader.getInstance().readFromVFile(file.getProject(), virtualFile); if (tree != null) { Stub root = tree.getRoot(); if (root instanceof FileStub) { return ((FileStub)root).getHeader(); } } } } if (!file.isValid()) return XmlFileHeader.EMPTY; return NanoXmlUtil.parseHeader(file); }
@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(); } }
protected DomFileElementImpl(final XmlFile file, final Class<T> rootElementClass, final EvaluatedXmlNameImpl rootTagName, final DomManagerImpl manager, final DomFileDescription<T> fileDescription, FileStub stub) { myFile = file; myRootElementClass = rootElementClass; myRootTagName = rootTagName; myManager = manager; myFileDescription = fileDescription; myRootHandler = new DomRootInvocationHandler(rootElementClass, new RootDomParentStrategy(this), this, rootTagName, stub == null ? null : stub.getRootTagStub()); }
@Override public Stub buildStubTree(FileContent fileContent) { VirtualFile file = fileContent.getFile(); Project project = fileContent.getProject(); PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) return null; XmlFile xmlFile = (XmlFile)psiFile; try { XmlUtil.BUILDING_DOM_STUBS.set(Boolean.TRUE); psiFile.putUserData(CONTENT_FOR_DOM_STUBS, fileContent); 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 " + file); } FileStub fileStub = new FileStub(header); DomStubBuilderVisitor visitor = new DomStubBuilderVisitor(fileStub); visitor.visitDomElement(fileElement.getRootElement()); return fileStub; } finally { XmlUtil.BUILDING_DOM_STUBS.set(Boolean.FALSE); psiFile.putUserData(CONTENT_FOR_DOM_STUBS, null); } }
@NotNull private static XmlFileHeader calcXmlFileHeader(final XmlFile file) { if (file instanceof PsiFileEx && ((PsiFileEx)file).isContentsLoaded() && file.getNode().isParsed()) { return computeHeaderByPsi(file); } if (!XmlUtil.isStubBuilding() && file.getFileType() == XmlFileType.INSTANCE) { VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile instanceof VirtualFileWithId) { ObjectStubTree tree = StubTreeLoader.getInstance().readFromVFile(file.getProject(), virtualFile); if (tree != null) { Stub root = tree.getRoot(); if (root instanceof FileStub) { return ((FileStub)root).getHeader(); } } } } if (!file.isValid()) return XmlFileHeader.EMPTY; if (XmlUtil.isStubBuilding() && file.getFileType() == XmlFileType.INSTANCE) { FileContent fileContent = file.getUserData(DomStubBuilder.CONTENT_FOR_DOM_STUBS); if (fileContent != null) { //noinspection IOResourceOpenedButNotSafelyClosed return NanoXmlUtil.parseHeader(new CharSequenceReader(fileContent.getContentAsText())); } } return NanoXmlUtil.parseHeader(file); }
public DomStubBuilderVisitor(FileStub fileStub) { myRoot = fileStub; }
@Override public Stub buildStubTree(FileContent fileContent) { VirtualFile file = fileContent.getFile(); Project project = fileContent.getProject(); PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if(!(psiFile instanceof XmlFile)) { return null; } XmlFile xmlFile = (XmlFile) psiFile; try { XmlUtil.BUILDING_DOM_STUBS.set(Boolean.TRUE); psiFile.putUserData(CONTENT_FOR_DOM_STUBS, fileContent); 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 " + file); } 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); psiFile.putUserData(CONTENT_FOR_DOM_STUBS, null); } }