void () { final XmlFile file = (XmlFile)createFile("file.xml", """ <?xml version='1.0' encoding='UTF-8'?> <a> <aboy> </aboy> <agirl/> </a>"""); final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class, "a"); myCallRegistry.clear(); final MyElement rootElement = fileElement.getRootElement(); assertNotNull(rootElement.getAboy().getXmlElement()); assertNotNull(rootElement.getAgirl().getXmlElement()); final MyElement oldBoy = rootElement.getAboy(); final XmlTag tag = oldBoy.getXmlTag(); assertNotNull(tag); final int offset = tag.getTextOffset(); final int endoffset = offset + tag.getTextLength(); WriteCommandAction.runWriteCommandAction(getProject(), () -> { rootElement.getAgirl().undefine(); final Document document = getDocument(file); PsiDocumentManager.getInstance(getProject()).doPostponedOperationsAndUnblockDocument(document); document.replaceString(offset + 1, offset + 1 + "aboy".length(), "agirl"); commitDocument(document); }); assertFalse(oldBoy.isValid()); assertNull(rootElement.getAboy().getXmlElement()); assertNotNull(rootElement.getAgirl().getXmlElement()); WriteCommandAction.runWriteCommandAction(getProject(), () -> { final Document document = getDocument(file); document.replaceString(endoffset - "aboy".length(), endoffset, "agirl"); commitDocument(document); }); assertNull(rootElement.getAboy().getXmlElement()); assertNotNull(rootElement.getAgirl().getXmlElement()); }