use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class DomSimpleValuesTest method testDefineAndSet.
public void testDefineAndSet() throws Throwable {
final MyElement element = getDomManager().getFileElement(createXmlFile(""), MyElement.class, "root").getRootElement();
myCallRegistry.clear();
assertNull(element.getXmlTag());
element.setValue(42);
assertNotNull(element.getXmlTag());
assertEquals("42", element.getXmlTag().getValue().getText());
final DomElement element1 = element;
myCallRegistry.putExpected(new DomEvent(element1, true));
myCallRegistry.putExpected(new DomEvent(element, false));
element.setValue((Integer) null);
assertNull(element.getXmlTag());
assertEquals(null, element.getValue());
myCallRegistry.putExpected(new DomEvent(element, false));
myCallRegistry.assertResultsAndClear();
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class DomSimpleValuesTest method testIndicators.
public void testIndicators() throws Throwable {
final MyElement element = createElement("<a><indicator/></a>");
final GenericDomValue<Boolean> indicator = element.getIndicator();
assertTrue(indicator.getValue());
indicator.setValue(false);
assertFalse(indicator.getValue());
assertNull(indicator.getStringValue());
assertNull(indicator.getXmlTag());
assertEquals(0, element.getXmlTag().getSubTags().length);
putExpected(new DomEvent(indicator, false));
assertResultsAndClear();
indicator.setValue(true);
assertTrue(indicator.getValue());
assertEquals("", indicator.getStringValue());
assertSame(indicator.getXmlTag(), element.getXmlTag().getSubTags()[0]);
final DomElement element1 = indicator;
putExpected(new DomEvent(element1, true));
assertResultsAndClear();
final XmlTag tag = element.getXmlTag();
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
tag.add(createTag("<indicator/>"));
tag.add(createTag("<indicator/>"));
}
}.execute();
assertTrue(element.isValid());
assertTrue(element.getIndicator().getValue());
element.getIndicator().setValue(false);
assertFalse(element.getIndicator().getValue());
assertEquals(0, element.getXmlTag().findSubTags("indicator").length);
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class DomVirtualFileEventsTest method testDeleteFile.
public void testDeleteFile() throws Throwable {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final VirtualFile dir = getVirtualFile(createTempDirectory());
addSourceContentToRoots(getModule(), dir);
final VirtualFile childData = dir.createChildData(this, "abc.xml");
assertResultsAndClear();
setFileText(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();
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class TreeIncrementalUpdateTest method testChangeImplementationClass_InCollection.
public void testChangeImplementationClass_InCollection() 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<MyElement>(getProject()) {
@Override
protected void run(@NotNull Result<MyElement> result) throws Throwable {
element.addChildElement().addChildElement();
}
}.execute().getResultObject();
final MyElement child = element.getChildElements().get(0);
final MyElement grandChild = child.getChildElements().get(0);
assertTrue(child instanceof BarInterface);
assertTrue(grandChild instanceof BarInterface);
assertTrue(element.isValid());
assertTrue(child.isValid());
assertTrue(grandChild.isValid());
assertNotNull(element.getXmlTag());
assertNotNull(child.getXmlTag());
final XmlTag tag = grandChild.getXmlTag();
assertNotNull(tag);
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(child.isValid());
final MyElement newChild = element.getChildElements().get(0);
assertTrue(newChild.isValid());
assertTrue(newChild.getClass().toString(), newChild instanceof BarInterface);
assertTrue(grandChild.isValid());
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 testAnotherChildren.
public void testAnotherChildren() throws Throwable {
final MyElement element = createElement("<a><child/></a>");
element.getXmlTag().add(createTag("<another-child/>"));
assertEquals(1, element.getAnotherChildren().size());
putExpected(new DomEvent(element, false));
assertResultsAndClear();
}
Aggregations