public void testDeleteFile() throws Throwable { new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { final VirtualFile dir = getVirtualFile(createTempDirectory()); PsiTestUtil.addSourceContentToRoots(getModule(), dir); final VirtualFile childData = dir.createChildData(this, "abc.xml"); assertResultsAndClear(); VfsUtil.saveText(childData, "<a/>"); final DomFileElementImpl<DomElement> fileElement = getFileElement(childData); assertResultsAndClear(); childData.delete(this); assertEventCount(1); putExpected(new DomEvent(fileElement, false)); assertResultsAndClear(); assertFalse(fileElement.isValid()); } }.execute().throwException(); }
public void testNonemptyRootTagPrefix() throws Throwable { getDomManager().registerFileDescription(new DomFileDescription<MyFooElement>(MyFooElement.class, "a", "foons") { @Override protected void initializeFileDescription() { super.initializeFileDescription(); registerNamespacePolicy("foo", "foons"); } }, getTestRootDisposable()); final XmlFile psiFile = createXmlFile("<f:a xmlns:f=\"foons\"/>"); final DomFileElementImpl<MyFooElement> element = getDomManager().getFileElement(psiFile, MyFooElement.class); assertNotNull(element); final MyFooElement root = element.getRootElement(); assertNotNull(root); assertSame(psiFile.getDocument().getRootTag(), root.getXmlElement()); }
public void testRenameFile() throws Throwable { new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { final VirtualFile dir = getVirtualFile(createTempDirectory()); PsiTestUtil.addSourceContentToRoots(getModule(), dir); final VirtualFile data = dir.createChildData(this, "abc.xml"); VfsUtil.saveText(data, "<a/>"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); final DomFileElementImpl<DomElement> fileElement = getFileElement(data); assertEventCount(0); assertResultsAndClear(); data.rename(this, "deaf.xml"); assertEventCount(1); putExpected(new DomEvent(fileElement, false)); assertResultsAndClear(); assertEquals(fileElement, getFileElement(data)); assertTrue(fileElement.isValid()); data.rename(this, "fff.xml"); assertEventCount(1); putExpected(new DomEvent(fileElement, false)); assertResultsAndClear(); assertNull(getFileElement(data)); assertFalse(fileElement.isValid()); } }.execute().throwException(); }
public void testRenameFile() throws Throwable { new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { final VirtualFile dir = getVirtualFile(createTempDirectory()); PsiTestUtil.addSourceContentToRoots(getModule(), dir); final VirtualFile data = dir.createChildData(this, "abc.xml"); VfsUtil.saveText(data, "<a/>"); final DomFileElementImpl<DomElement> fileElement = getFileElement(data); assertEventCount(0); assertResultsAndClear(); data.rename(this, "deaf.xml"); assertEventCount(1); putExpected(new DomEvent(fileElement, false)); assertResultsAndClear(); assertEquals(fileElement, getFileElement(data)); assertTrue(fileElement.isValid()); data.rename(this, "fff.xml"); assertEventCount(1); putExpected(new DomEvent(fileElement, false)); assertResultsAndClear(); assertNull(getFileElement(data)); assertFalse(fileElement.isValid()); } }.execute().throwException(); }
private DomFileElementImpl<DomElement> getFileElement(final VirtualFile file) { return getDomManager().getFileElement((XmlFile)getPsiManager().findFile(file)); }
private MyElement createDomFile(final String fileName, final String fileText) throws IOException { final XmlFile xmlFile = (XmlFile) createFile(fileName, fileText); final DomFileElementImpl<MyElement> element = getDomManager().getFileElement(xmlFile, MyElement.class, xmlFile.getDocument().getRootTag().getName()); return element.getRootElement(); }
protected void assertCached(final DomFileElementImpl element, final XmlFile file) { assertNotNull(file); assertEquals(element, getDomManager().getFileElement(file)); }