Search in sources :

Example 41 with DomEvent

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

Example 42 with DomEvent

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

Example 43 with DomEvent

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());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) Document(com.intellij.openapi.editor.Document) XmlTag(com.intellij.psi.xml.XmlTag) Result(com.intellij.openapi.application.Result) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 44 with DomEvent

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

Example 45 with DomEvent

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();
}
Also used : 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