use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class TreeIncrementalUpdateTest method testAddCollectionElement.
public void testAddCollectionElement() throws Throwable {
final MyElement element = createElement("<a><child/><child/><child-element/></a>");
final MyElement child = element.getChild();
final MyElement child2 = element.getChild2();
final MyElement firstChild = element.getChildElements().get(0);
element.getXmlTag().add(createTag("<child-element/>"));
final XmlTag[] subTags = element.getXmlTag().getSubTags();
assertEquals(2, element.getChildElements().size());
assertEquals(firstChild, element.getChildElements().get(0));
MyElement nextChild = element.getChildElements().get(1);
putExpected(new DomEvent(element, false));
assertResultsAndClear();
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class TreeIncrementalUpdateTest method testChangeImplementationClass.
public void testChangeImplementationClass() throws Throwable {
getTypeChooserManager().registerTypeChooser(MyElement.class, createClassChooser());
try {
final MyElement element = getDomManager().createMockElement(MyElement.class, getModule(), true);
final DomFileElement<MyElement> root = DomUtil.getFileElement(element);
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
element.addChildElement().addChildElement();
}
}.execute();
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();
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
tag.add(XmlElementFactory.getInstance(getProject()).createTagFromText("<foo/>"));
}
}.execute();
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);
}
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class TreeIncrementalUpdateTest method testDocumentChange.
public void testDocumentChange() throws Throwable {
final XmlFile file = (XmlFile) createFile("file.xml", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<a>\n" + " <child>\n" + " <child/>\n" + " </child>\n" + "</a>");
final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class, "a");
myCallRegistry.clear();
final MyElement rootElement = fileElement.getRootElement();
final MyElement oldLeaf = rootElement.getChild().getChild();
final XmlTag oldLeafTag = oldLeaf.getXmlTag();
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final Document document = getDocument(file);
document.replaceString(0, document.getText().length(), "<a/>");
commitDocument(document);
}
}.execute();
assertFalse(oldLeafTag.isValid());
putExpected(new DomEvent(fileElement, false));
assertResultsAndClear();
assertEquals(fileElement.getRootElement(), rootElement);
assertTrue(rootElement.isValid());
assertFalse(oldLeaf.isValid());
assertTrue(rootElement.getChild().isValid());
assertNull(rootElement.getChild().getXmlTag());
assertNull(rootElement.getChild().getChild().getXmlTag());
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class TreeIncrementalUpdateTest method testDocumentChange2.
public void testDocumentChange2() throws Throwable {
final XmlFile file = (XmlFile) createFile("file.xml", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<!DOCTYPE ejb-jar PUBLIC \"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN\" \"http://java.sun.com/dtd/ejb-jar_2_0.dtd\">\n" + "<a>\n" + " <child>\n" + " <child/>\n" + " </child>\n" + "</a>");
final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class, "a");
myCallRegistry.clear();
final MyElement rootElement = fileElement.getRootElement();
final MyElement oldLeaf = rootElement.getChild().getChild();
final XmlTag oldLeafTag = oldLeaf.getXmlTag();
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
file.getDocument().getProlog().delete();
final XmlTag tag = file.getDocument().getRootTag();
tag.setAttribute("xmlns", "something");
tag.setAttribute("xmlns:xsi", "something");
}
}.execute();
assertTrue(oldLeafTag.isValid());
putExpected(new DomEvent(fileElement, false));
putExpected(new DomEvent(rootElement, false));
putExpected(new DomEvent(rootElement, false));
assertResultsAndClear();
assertEquals(fileElement.getRootElement(), rootElement);
assertTrue(rootElement.isValid());
assertTrue(rootElement.getChild().isValid());
assertTrue(rootElement.getChild().getXmlTag().isValid());
assertTrue(rootElement.getChild().getChild().getXmlTag().isValid());
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class SimpleValuesIncrementalUpdateTest method testTagValueChange.
public void testTagValueChange() throws Throwable {
final MyElement element = createElement("<a><child> </child></a>").getChild();
element.getXmlTag().getValue().setText("abc");
putExpected(new DomEvent(element, false));
assertResultsAndClear();
element.getXmlTag().getValue().setText(null);
putExpected(new DomEvent(element, false));
assertResultsAndClear();
}
Aggregations