Search in sources :

Example 36 with DomEvent

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

Example 37 with DomEvent

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

Example 38 with DomEvent

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

Example 39 with DomEvent

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

Example 40 with DomEvent

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