Search in sources :

Example 21 with DomEvent

use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.

the class TreeIncrementalUpdateTest method testTypeBeforeRootTag.

public void testTypeBeforeRootTag() throws Throwable {
    getDomManager().registerFileDescription(new DomFileDescription<>(MyElement.class, "a"), getTestRootDisposable());
    final XmlFile file = (XmlFile) createFile("file.xml", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<a/>");
    assertTrue(getDomManager().isDomFile(file));
    final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class);
    assertTrue(fileElement.isValid());
    myCallRegistry.clear();
    putExpected(new DomEvent(fileElement, false));
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final Document document = getDocument(file);
            final int i = document.getText().indexOf("<a");
            document.insertString(i, "a");
            commitDocument(document);
        }
    }.execute();
    assertFalse(getDomManager().isDomFile(file));
    assertFalse(fileElement.isValid());
    assertResultsAndClear();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) Document(com.intellij.openapi.editor.Document) DomEvent(com.intellij.util.xml.events.DomEvent) Result(com.intellij.openapi.application.Result)

Example 22 with DomEvent

use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.

the class TreeIncrementalUpdateTest method testRemoveFixedElement.

public void testRemoveFixedElement() throws Throwable {
    final MyElement element = createElement("<a>" + "<child/>" + "<child><child/></child>" + "<child><child/></child>" + "</a>");
    final MyElement child = element.getChild();
    final MyElement child2 = element.getChild2();
    final MyElement oldLeaf = child2.getChild();
    final XmlTag tag = element.getXmlTag();
    XmlTag leafTag = tag.getSubTags()[2].getSubTags()[0];
    assertNoCache(leafTag);
    ApplicationManager.getApplication().runWriteAction(() -> {
        tag.getSubTags()[1].delete();
        assertFalse(oldLeaf.isValid());
        putExpected(new DomEvent(element, false));
        assertResultsAndClear();
        assertEquals(child, element.getChild());
        assertFalse(child2.isValid());
        tag.getSubTags()[1].delete();
    });
    putExpected(new DomEvent(element, false));
    assertResultsAndClear();
}
Also used : XmlTag(com.intellij.psi.xml.XmlTag) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 23 with DomEvent

use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.

the class TreeIncrementalUpdateTest method testActuallyRemoveCollectionElement.

public void testActuallyRemoveCollectionElement() throws Throwable {
    final MyElement element = createElement("<a><child-element><child/></child-element><child-element/></a>");
    final MyElement child = element.getChild();
    final MyElement child2 = element.getChild2();
    final MyElement firstChild = element.getChildElements().get(0);
    final MyElement lastChild = element.getChildElements().get(1);
    final XmlTag tag = element.getXmlTag();
    final XmlTag childTag = tag.getSubTags()[0];
    WriteCommandAction.runWriteCommandAction(null, () -> childTag.delete());
    putExpected(new DomEvent(element, false));
    assertResultsAndClear();
    assertEquals(child, element.getChild());
    assertEquals(child2, element.getChild2());
    assertEquals(Arrays.asList(lastChild), element.getChildElements());
    assertCached(lastChild, tag.getSubTags()[0]);
}
Also used : XmlTag(com.intellij.psi.xml.XmlTag) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 24 with DomEvent

use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.

the class DomBasicsTest method testEnsureTagExists.

public void testEnsureTagExists() throws Throwable {
    final MyElement element = createElement("<a/>");
    myCallRegistry.clear();
    final MyElement child = element.getChild();
    assertNull(child.getXmlTag());
    child.ensureTagExists();
    final XmlTag[] subTags = element.getXmlTag().getSubTags();
    assertEquals(1, subTags.length);
    final XmlTag childTag = subTags[0];
    assertEquals("child", childTag.getName());
    assertCached(child, childTag);
    assertSame(child.getXmlTag(), childTag);
    final DomElement element1 = child;
    myCallRegistry.putExpected(new DomEvent(element1, true));
    myCallRegistry.assertResultsAndClear();
    final MyElement childElement = element.addChildElement();
    final XmlTag childElementTag = childElement.getXmlTag();
    assertSame(childElementTag, childElement.ensureTagExists());
}
Also used : XmlTag(com.intellij.psi.xml.XmlTag) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 25 with DomEvent

use of com.intellij.util.xml.events.DomEvent in project intellij-community by JetBrains.

the class DomBasicsTest method testEnsureRootTagExists.

public void testEnsureRootTagExists() throws Throwable {
    final MyElement rootElement = createEmptyElement();
    myCallRegistry.clear();
    assertNull(rootElement.getXmlTag());
    rootElement.ensureTagExists();
    final DomElement element = rootElement;
    myCallRegistry.putExpected(new DomEvent(element, true));
    assertCached(rootElement, assertRootTag(rootElement));
    myCallRegistry.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