void () { ApplicationManager.getApplication().runWriteAction(() -> XmlElementFactory.getInstance(getProject()).createTagFromText("<a/>").getValue().setText("@#$%@$%$${${''}")); } public void testPsiToDocumentSynchronizationFailed() throws Throwable { String text = "<wpd><methods> </methods></wpd>"; final File tempFile = FileUtil.createTempFile("idea-test", ".xml"); tempFile.createNewFile(); FileUtil.writeToFile(tempFile, text); ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(getProject(), () -> { VirtualFileManager.getInstance().syncRefresh(); XmlFile file ;//createTemporaryFile("wpd.xml", text)); try { file = (XmlFile)getPsiManager().findFile(VfsUtil.findFileByURL(tempFile.toURL())); } catch (MalformedURLException e) { throw new RuntimeException(e); } final XmlTag methodTag = file.getDocument().getRootTag().findFirstSubTag("methods"); try { methodTag.add(XmlElementFactory.getInstance(getProject()).createTagFromText("<method/>")); } catch (IncorrectOperationException e) { throw new RuntimeException(e); } }, "", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION)); } public void testXmlFormattingException() { final XmlTag tag = XmlElementFactory.getInstance(getProject()).createTagFromText("<foo>bar</foo>"); ApplicationManager.getApplication().runWriteAction(() -> { tag.add(XmlElementFactory.getInstance(getProject()).createTagFromText("<bar/>")); }); } public void testSetNamespace() { XmlFile xhtmlFile = (XmlFile)PsiFileFactory.getInstance(getProject()).createFileFromText("dummy.xml", "<html><body/></html>"); final XmlTag rootTag = xhtmlFile.getDocument().getRootTag(); rootTag.getSubTags()[0].getNamespace(); // fill the cache ApplicationManager.getApplication().runWriteAction(() -> { rootTag.setAttribute("xmlns", "http://www.ru"); }); assertEquals("http://www.ru", rootTag.getSubTags()[0].getNamespace()); } public void testInsert() { String html = "<html><head /><body><hr /></body>\n</html>"; XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()).createFileFromText("xxx.xhtml", html); XmlTag body = file.getDocument().getRootTag().findFirstSubTag("body"); final XmlTag hr = body.getSubTags()[0]; final XmlText text = XmlElementFactory.getInstance(getProject()).createDisplayText("p"); ApplicationManager.getApplication().runWriteAction(() -> { PsiElement element = hr.getParentTag().addAfter(text, hr); assertEquals(element.getParent(), hr.getParentTag()); }); } public void testCollapse() throws IncorrectOperationException { final XmlTag tag = XmlElementFactory.getInstance(getProject()).createTagFromText("<foo></foo>"); ApplicationManager.getApplication().runWriteAction(() -> { tag.collapseIfEmpty(); assertEquals("<foo/>", tag.getText()); final XmlTag tag1 = XmlElementFactory.getInstance(getProject()).createTagFromText("<foo>abc</foo>"); tag1.collapseIfEmpty(); assertEquals("<foo/>", tag1.getText()); final XmlTag tag2 = XmlElementFactory.getInstance(getProject()).createTagFromText("<foo><boo/></foo>"); tag2.collapseIfEmpty(); assertEquals("<foo><boo/></foo>", tag2.getText()); }); } public void testSetName() { XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()).createFileFromText("dummy.xml", XmlFileType.INSTANCE, "<fooBarGoo>1</fooBarGoo>", 0, true); final XmlTag tag = file.getDocument().getRootTag(); final Document document = file.getViewProvider().getDocument(); ApplicationManager.getApplication().runWriteAction(() -> { tag.setName("xxx"); assertEquals("<xxx>1</xxx>", tag.getText()); assertEquals("<xxx>1</xxx>", document.getText()); }); } public void testSetAttributeValue() { XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()).createFileFromText("dummy.xml", XmlFileType.INSTANCE, "<fooBarGoo attr>1</fooBarGoo>", 0, true); final XmlTag tag = file.getDocument().getRootTag(); final Document document = file.getViewProvider().getDocument(); ApplicationManager.getApplication().runWriteAction(() -> { tag.setAttribute("attr", ""); assertEquals("<fooBarGoo attr=\"\">1</fooBarGoo>", tag.getText()); assertEquals("<fooBarGoo attr=\"\">1</fooBarGoo>", document.getText()); }); } }