void () { getTypeChooserManager().registerTypeChooser(MyElement.class, createClassChooser()); try { final MyElement element = getDomManager().createMockElement(MyElement.class, getModule(), true); final DomFileElement<MyElement> root = DomUtil.getFileElement(element); WriteCommandAction.runWriteCommandAction(getProject(), () -> { element.addChildElement().addChildElement(); }); final MyElement child = element.getChildElements().get(0); MyElement grandChild = child.getChildElements().get(0); assertTrue(child instanceof BarInterface); assertTrue(grandChild instanceof BarInterface); grandChild = element.getChildElements().get(0).getChildElements().get(0); final XmlTag tag = grandChild.getXmlTag(); assertTrue(grandChild.isValid()); assertEquals(grandChild, root.getRootElement().getChildElements().get(0).getChildElements().get(0)); assertNotNull(element.getXmlTag()); assertNotNull(child.getXmlTag()); assertNotNull(tag); assertTrue(tag.isValid()); myCallRegistry.clear(); WriteCommandAction.runWriteCommandAction(getProject(), () -> { tag.add(XmlElementFactory.getInstance(getProject()).createTagFromText("<foo/>")); }); assertTrue(root.isValid()); assertTrue(element.isValid()); assertTrue(grandChild.isValid()); final MyElement newChild = root.getRootElement().getChildElements().get(0); assertTrue(newChild instanceof BarInterface); final MyElement newGrandChild = newChild.getChildElements().get(0); assertTrue(newGrandChild.isValid()); assertTrue(newGrandChild instanceof FooInterface); putExpected(new DomEvent(child, false)); putExpected(new DomEvent(grandChild, false)); assertResultsAndClear(); } finally { getTypeChooserManager().unregisterTypeChooser(MyElement.class); } }