Search in sources :

Example 26 with DomEvent

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();
}
Also used : XmlTag(com.intellij.psi.xml.XmlTag) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 27 with DomEvent

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();
}
Also used : DomEvent(com.intellij.util.xml.events.DomEvent) XmlTag(com.intellij.psi.xml.XmlTag)

Example 28 with DomEvent

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]);
}
Also used : XmlTag(com.intellij.psi.xml.XmlTag) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 29 with DomEvent

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();
}
Also used : DomEvent(com.intellij.util.xml.events.DomEvent)

Example 30 with DomEvent

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);
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) DomElement(com.intellij.util.xml.DomElement) IncorrectOperationException(com.intellij.util.IncorrectOperationException) DomEvent(com.intellij.util.xml.events.DomEvent)

Aggregations

DomEvent (com.intellij.util.xml.events.DomEvent)48 XmlTag (com.intellij.psi.xml.XmlTag)24 Result (com.intellij.openapi.application.Result)7 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)7 XmlFile (com.intellij.psi.xml.XmlFile)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 DomElement (com.intellij.util.xml.DomElement)3 Document (com.intellij.openapi.editor.Document)2 XmlAttribute (com.intellij.psi.xml.XmlAttribute)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 DomSupportEnabled (com.intellij.ide.highlighter.DomSupportEnabled)1 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)1 ObjectStubTree (com.intellij.psi.stubs.ObjectStubTree)1 FileStub (com.intellij.util.xml.stubs.FileStub)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1