use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class DomChildrenTest method testDefiningIndexedChild.
public void testDefiningIndexedChild() throws Throwable {
final MyElement element = createElement("<a/>");
final XmlTag tag = element.getChild2().ensureTagExists();
final XmlTag[] subTags = element.getXmlTag().findSubTags("child");
assertEquals(2, subTags.length);
assertSame(tag, subTags[1]);
assertCached(element.getChild(), subTags[0]);
final DomElement element1 = element.getChild();
putExpected(new DomEvent(element1, true));
final DomElement element2 = element.getChild().getAttr();
putExpected(new DomEvent(element2, true));
final DomElement element3 = element.getChild().isGenericValue();
putExpected(new DomEvent(element3, true));
final DomElement element4 = element.getChild2();
putExpected(new DomEvent(element4, true));
final DomElement element5 = element.getChild2().getAttr();
putExpected(new DomEvent(element5, true));
final DomElement element6 = element.getChild2().isGenericValue();
putExpected(new DomEvent(element6, true));
assertResultsAndClear();
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class DomChildrenTest method testUndefineLastFixedChild.
public void testUndefineLastFixedChild() throws Throwable {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final MyElement element = createElement("<a>" + "<child>1</child>" + "<child attr=\"\">2</child>" + "<child attr=\"\">2</child>" + "</a>");
final MyElement child = element.getChild();
final MyElement child2 = element.getChild2();
child2.undefine();
myCallRegistry.putExpected(new DomEvent(child2, false));
myCallRegistry.assertResultsAndClear();
XmlTag[] subTags = element.getXmlTag().getSubTags();
assertTrue(child.isValid());
assertTrue(child2.isValid());
assertEquals(1, subTags.length);
assertNull(child2.getXmlTag());
assertEquals(element, child.getParent());
assertEquals(element, child2.getParent());
}
}.execute().throwException();
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class DomChildrenTest method testAddChild.
public void testAddChild() throws Throwable {
final MyElement element = createElement("<a><child-element/></a>");
assertEquals(1, element.getChildElements().size());
final MyElement firstChild = element.getChildElements().get(0);
final XmlTag firstChildTag = element.getXmlTag().findSubTags("child-element")[0];
assertCached(firstChild, firstChildTag);
final MyElement child = element.addChildElement();
assertEquals(Arrays.asList(firstChild, child), element.getChildElements());
final XmlTag childTag = element.getXmlTag().findSubTags("child-element")[1];
putExpected(new DomEvent(element, false));
final DomElement element1 = child.getAttr();
putExpected(new DomEvent(element1, true));
final DomElement element2 = child.isGenericValue();
putExpected(new DomEvent(element2, true));
final MyElement newChild = element.addChildElement(1);
assertEquals(Arrays.asList(firstChild, newChild, child), element.getChildElements());
final XmlTag newChildTag = element.getXmlTag().findSubTags("child-element")[1];
putExpected(new DomEvent(element, false));
final DomElement element3 = newChild.getAttr();
putExpected(new DomEvent(element3, true));
final DomElement element4 = newChild.isGenericValue();
putExpected(new DomEvent(element4, true));
final MyElement lastChild = element.addChildElement(239);
assertEquals(Arrays.asList(firstChild, newChild, child, lastChild), element.getChildElements());
final XmlTag lastChildTag = element.getXmlTag().findSubTags("child-element")[3];
putExpected(new DomEvent(element, false));
final DomElement element5 = lastChild.getAttr();
putExpected(new DomEvent(element5, true));
final DomElement element6 = lastChild.isGenericValue();
putExpected(new DomEvent(element6, true));
assertResultsAndClear();
assertCached(firstChild, firstChildTag);
assertCached(newChild, newChildTag);
assertCached(child, childTag);
assertCached(lastChild, lastChildTag);
assertSame(firstChildTag, element.getXmlTag().findSubTags("child-element")[0]);
assertSame(newChildTag, element.getXmlTag().findSubTags("child-element")[1]);
assertSame(childTag, element.getXmlTag().findSubTags("child-element")[2]);
assertSame(lastChildTag, element.getXmlTag().findSubTags("child-element")[3]);
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class DomChildrenTest method testUndefineLastFixedChildWithNotEmptyCollection.
public void testUndefineLastFixedChildWithNotEmptyCollection() throws Throwable {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final MyElement element = createElement("<a>" + "<child>1</child>" + "<child attr=\"\">2</child>" + "<child/></a>");
final MyElement child = element.getChild();
final MyElement child2 = element.getChild2();
assertEquals("", child2.getAttr().getValue());
assertTrue(child.isValid());
assertTrue(child2.isValid());
child.undefine();
assertTrue(child.isValid());
assertTrue(child2.isValid());
assertTrue(child2.equals(element.getChild2()));
assertNotNull(child.getXmlTag());
child2.undefine();
assertTrue(child.isValid());
assertTrue(child2.isValid());
assertTrue(child2.equals(element.getChild2()));
assertEquals(child, element.getChild());
assertEquals("", child.getValue());
assertNull(element.getChild2().getValue());
myCallRegistry.putExpected(new DomEvent(child, false));
myCallRegistry.putExpected(new DomEvent(child2, false));
myCallRegistry.assertResultsAndClear();
}
}.execute().throwException();
}
use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.
the class AttributeChildInvocationHandler method ensureXmlElementExists.
@Override
public final XmlAttribute ensureXmlElementExists() {
XmlAttribute attribute = (XmlAttribute) getXmlElement();
if (attribute != null)
return attribute;
final DomManagerImpl manager = getManager();
final boolean b = manager.setChanging(true);
try {
attribute = ensureTagExists().setAttribute(getXmlElementName(), getXmlApiCompatibleNamespace(getParentHandler()), "");
setXmlElement(attribute);
getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, this);
final DomElement element = getProxy();
manager.fireEvent(new DomEvent(element, true));
return attribute;
} catch (IncorrectOperationException e) {
LOG.error(e);
return null;
} finally {
manager.setChanging(b);
}
}
Aggregations