Java 类com.intellij.util.xml.events.DomEvent 实例源码

项目:intellij-ce-playground    文件:DomInvocationHandler.java   
@Override
public XmlTag ensureTagExists() {
  assertValid();

  XmlTag tag = getXmlTag();
  if (tag != null) return tag;

  tag = setEmptyXmlTag();
  setXmlElement(tag);

  final DomElement element = getProxy();
  myManager.fireEvent(new DomEvent(element, true));
  addRequiredChildren();
  myManager.cacheHandler(getCacheKey(), tag, this);
  return getXmlTag();
}
项目:intellij-ce-playground    文件:AttributeChildInvocationHandler.java   
@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);
  }
}
项目:intellij-ce-playground    文件:AttributeChildInvocationHandler.java   
@Override
protected void setValue(@Nullable final String value) {
  final XmlTag tag = ensureTagExists();
  final String attributeName = getXmlElementName();
  final String namespace = getXmlApiCompatibleNamespace(getParentHandler());
  final String oldValue = StringUtil.unescapeXml(tag.getAttributeValue(attributeName, namespace));
  final String newValue = XmlStringUtil.escapeString(value);
  if (Comparing.equal(oldValue, newValue, true)) return;

  getManager().runChange(new Runnable() {
    @Override
    public void run() {
      try {
        XmlAttribute attribute = tag.setAttribute(attributeName, namespace, newValue);
        setXmlElement(attribute);
        getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, AttributeChildInvocationHandler.this);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  });
  final DomElement proxy = getProxy();
  getManager().fireEvent(oldValue != null ? new DomEvent(proxy, false) : new DomEvent(proxy, true));
}
项目:intellij-ce-playground    文件:DomBasicsTest.java   
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());
}
项目:intellij-ce-playground    文件:DomVirtualFileEventsTest.java   
public void testDeleteFile() throws Throwable {
  new WriteCommandAction.Simple(getProject()) {
    @Override
    protected void run() throws Throwable {
      final VirtualFile dir = getVirtualFile(createTempDirectory());
      PsiTestUtil.addSourceContentToRoots(getModule(), dir);
      final VirtualFile childData = dir.createChildData(this, "abc.xml");
      assertResultsAndClear();
      VfsUtil.saveText(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();
}
项目:intellij-ce-playground    文件:DomChildrenTest.java   
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();
}
项目:intellij-ce-playground    文件:DomChildrenTest.java   
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();
}
项目:intellij-ce-playground    文件:SimpleValuesIncrementalUpdateTest.java   
public void testAttributeChange() throws Throwable {
  final MyElement element = createElement("<a/>");
  element.getXmlTag().setAttribute("attr", "foo");
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();
  assertTrue(element.getAttr().isValid());

  element.getXmlTag().setAttribute("bttr", "foo");
  element.getXmlTag().setAttribute("attr", "bar");
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();
  assertTrue(element.getAttr().isValid());

  element.getXmlTag().setAttribute("attr", null);
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();
  assertTrue(element.getAttr().isValid());
}
项目:intellij-ce-playground    文件:DomSimpleValuesTest.java   
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();
}
项目:intellij-ce-playground    文件:TreeIncrementalUpdateTest.java   
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, new Runnable() {
    @Override
    public void run() {
      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]);
}
项目:intellij-ce-playground    文件:TreeIncrementalUpdateTest.java   
public void testCustomChildrenEvents() throws Throwable {
  final Sepulka element = createElement("<a><foo/><bar/></a>", Sepulka.class);
  final List<MyElement> list = element.getCustomChildren();
  final XmlTag tag = element.getXmlTag();
  WriteCommandAction.runWriteCommandAction(null, new Runnable(){
    @Override
    public void run() {
      tag.getSubTags()[0].delete();
      tag.getSubTags()[0].delete();
    }
  });

  tag.add(createTag("<goo/>"));
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();

  assertEquals(1, element.getCustomChildren().size());
}
项目:intellij-ce-playground    文件:IncrementalUpdateEventsTest.java   
public void testRemove0() {
  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();

  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();

  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();

  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();
}
项目:tools-idea    文件:AttributeChildInvocationHandler.java   
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);
  }
}
项目:tools-idea    文件:AttributeChildInvocationHandler.java   
protected void setValue(@Nullable final String value) {
  final XmlTag tag = ensureTagExists();
  final String attributeName = getXmlElementName();
  final String namespace = getXmlApiCompatibleNamespace(getParentHandler());
  final String oldValue = StringUtil.unescapeXml(tag.getAttributeValue(attributeName, namespace));
  final String newValue = XmlStringUtil.escapeString(value);
  if (Comparing.equal(oldValue, newValue, true)) return;

  getManager().runChange(new Runnable() {
    public void run() {
      try {
        XmlAttribute attribute = tag.setAttribute(attributeName, namespace, newValue);
        setXmlElement(attribute);
        getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, AttributeChildInvocationHandler.this);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  });
  final DomElement proxy = getProxy();
  final DomElement element = proxy;
  getManager().fireEvent(oldValue != null ? new DomEvent(proxy, false) : new DomEvent(element, true));
}
项目:tools-idea    文件:DomBasicsTest.java   
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());
}
项目:tools-idea    文件:DomVirtualFileEventsTest.java   
public void testDeleteFile() throws Throwable {
  new WriteCommandAction.Simple(getProject()) {
    @Override
    protected void run() throws Throwable {
      final VirtualFile dir = getVirtualFile(createTempDirectory());
      PsiTestUtil.addSourceContentToRoots(getModule(), dir);
      final VirtualFile childData = dir.createChildData(this, "abc.xml");
      assertResultsAndClear();
      VfsUtil.saveText(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();
}
项目:tools-idea    文件:DomChildrenTest.java   
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();
}
项目:tools-idea    文件:DomChildrenTest.java   
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();
}
项目:tools-idea    文件:SimpleValuesIncrementalUpdateTest.java   
public void testAttributeChange() throws Throwable {
  final MyElement element = createElement("<a/>");
  element.getXmlTag().setAttribute("attr", "foo");
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();
  assertTrue(element.getAttr().isValid());

  element.getXmlTag().setAttribute("bttr", "foo");
  element.getXmlTag().setAttribute("attr", "bar");
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();
  assertTrue(element.getAttr().isValid());

  element.getXmlTag().setAttribute("attr", null);
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();
  assertTrue(element.getAttr().isValid());
}
项目:tools-idea    文件:DomSimpleValuesTest.java   
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();
}
项目:tools-idea    文件:TreeIncrementalUpdateTest.java   
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];
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    public void run() {
      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]);
}
项目:tools-idea    文件:TreeIncrementalUpdateTest.java   
public void testCustomChildrenEvents() throws Throwable {
  final Sepulka element = createElement("<a><foo/><bar/></a>", Sepulka.class);
  final List<MyElement> list = element.getCustomChildren();
  final XmlTag tag = element.getXmlTag();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    public void run() {
      tag.getSubTags()[0].delete();
      tag.getSubTags()[0].delete();
    }
  });

  tag.add(createTag("<goo/>"));
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();

  assertEquals(1, element.getCustomChildren().size());
}
项目:tools-idea    文件:IncrementalUpdateEventsTest.java   
public void testRemove0() throws IncorrectOperationException {
  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();

  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();

  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();

  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();
}
项目:consulo-xml    文件:AttributeChildInvocationHandler.java   
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);
  }
}
项目:consulo-xml    文件:AttributeChildInvocationHandler.java   
protected void setValue(@Nullable final String value) {
  final XmlTag tag = ensureTagExists();
  final String attributeName = getXmlElementName();
  final String namespace = getXmlApiCompatibleNamespace(getParentHandler());
  final String oldValue = StringUtil.unescapeXml(tag.getAttributeValue(attributeName, namespace));
  final String newValue = XmlStringUtil.escapeString(value);
  if (Comparing.equal(oldValue, newValue, true)) return;

  getManager().runChange(new Runnable() {
    public void run() {
      try {
        XmlAttribute attribute = tag.setAttribute(attributeName, namespace, newValue);
        setXmlElement(attribute);
        getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, AttributeChildInvocationHandler.this);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  });
  final DomElement proxy = getProxy();
  final DomElement element = proxy;
  getManager().fireEvent(oldValue != null ? new DomEvent(proxy, false) : new DomEvent(element, true));
}
项目:consulo-xml    文件:DomBasicsTest.java   
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());
}
项目:consulo-xml    文件:DomChildrenTest.java   
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();
}
项目:consulo-xml    文件:DomChildrenTest.java   
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();
}
项目:consulo-xml    文件:SimpleValuesIncrementalUpdateTest.java   
public void testAttributeChange() throws Throwable {
  final MyElement element = createElement("<a/>");
  element.getXmlTag().setAttribute("attr", "foo");
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();
  assertTrue(element.getAttr().isValid());

  element.getXmlTag().setAttribute("bttr", "foo");
  element.getXmlTag().setAttribute("attr", "bar");
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();
  assertTrue(element.getAttr().isValid());

  element.getXmlTag().setAttribute("attr", null);
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();
  assertTrue(element.getAttr().isValid());
}
项目:consulo-xml    文件:TreeIncrementalUpdateTest.java   
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];
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    public void run() {
      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]);
}
项目:consulo-xml    文件:TreeIncrementalUpdateTest.java   
public void testCustomChildrenEvents() throws Throwable {
  final Sepulka element = createElement("<a><foo/><bar/></a>", Sepulka.class);
  final List<MyElement> list = element.getCustomChildren();
  final XmlTag tag = element.getXmlTag();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    public void run() {
      tag.getSubTags()[0].delete();
      tag.getSubTags()[0].delete();
    }
  });

  tag.add(createTag("<goo/>"));
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();

  assertEquals(1, element.getCustomChildren().size());
}
项目:consulo-xml    文件:IncrementalUpdateEventsTest.java   
public void testRemove0() throws IncorrectOperationException {
  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();

  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();

  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();

  deleteTag(0);
  putExpected(new DomEvent(myElement, false));
  assertResultsAndClear();
}
项目:intellij-ce-playground    文件:DomInvocationHandler.java   
protected void setValue(@Nullable final String value) {
  final XmlTag tag = ensureTagExists();
  myManager.runChange(new Runnable() {
    @Override
    public void run() {
      setTagValue(tag, value);
    }
  });
  myManager.fireEvent(new DomEvent(getProxy(), false));
}
项目:intellij-ce-playground    文件:DomInvocationHandler.java   
public final DomElement addCollectionChild(final CollectionChildDescriptionImpl description, final Type type, int index) throws IncorrectOperationException {
  final EvaluatedXmlName name = createEvaluatedXmlName(description.getXmlName());
  final XmlTag tag = addEmptyTag(name, index);
  final CollectionElementInvocationHandler handler = new CollectionElementInvocationHandler(type, tag, description, this, null);
  myManager.fireEvent(new DomEvent(getProxy(), false));
  getManager().getTypeChooserManager().getTypeChooser(description.getType()).distinguishTag(tag, type);
  handler.addRequiredChildren();
  return handler.getProxy();
}
项目:intellij-ce-playground    文件:CollectionElementInvocationHandler.java   
@Override
public final void undefineInternal() {
  final DomElement parent = getParent();
  final XmlTag tag = getXmlTag();
  if (tag == null) return;

  getManager().cacheHandler(getCacheKey(), tag, null);
  setXmlElement(null);
  deleteTag(tag);
  getManager().fireEvent(new DomEvent(parent, false));
}
项目:intellij-ce-playground    文件:DomFileEditor.java   
@Override
@NotNull
protected JComponent createCustomComponent() {
  MnemonicHelper.init(getComponent());
  myComponent = myComponentFactory.create();
  DomUIFactory.getDomUIFactory().setupErrorOutdatingUserActivityWatcher(this, getDomElement());
  DomManager.getDomManager(getProject()).addDomEventListener(new DomEventListener() {
    @Override
    public void eventOccured(DomEvent event) {
      checkIsValid();
    }
  }, this);
  Disposer.register(this, myComponent);
  return myComponent.getComponent();
}
项目:intellij-ce-playground    文件:DomBasicsTest.java   
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();
}
项目:intellij-ce-playground    文件:DomVirtualFileEventsTest.java   
public void testRenameFile() throws Throwable {
  new WriteCommandAction.Simple(getProject()) {
    @Override
    protected void run() throws Throwable {
      final VirtualFile dir = getVirtualFile(createTempDirectory());
      PsiTestUtil.addSourceContentToRoots(getModule(), dir);
      final VirtualFile data = dir.createChildData(this, "abc.xml");
      VfsUtil.saveText(data, "<a/>");
      PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
      final DomFileElementImpl<DomElement> fileElement = getFileElement(data);
      assertEventCount(0);
      assertResultsAndClear();

      data.rename(this, "deaf.xml");
      assertEventCount(1);
      putExpected(new DomEvent(fileElement, false));
      assertResultsAndClear();
      assertEquals(fileElement, getFileElement(data));
      assertTrue(fileElement.isValid());

      data.rename(this, "fff.xml");
      assertEventCount(1);
      putExpected(new DomEvent(fileElement, false));
      assertResultsAndClear();
      assertNull(getFileElement(data));
      assertFalse(fileElement.isValid());
    }
  }.execute().throwException();
}
项目:intellij-ce-playground    文件:DomHardCoreTestCase.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  myCallRegistry = new CallRegistry<DomEvent>();
  getDomManager().addDomEventListener(new DomEventListener() {
    @Override
    public void eventOccured(DomEvent event) {
      myCallRegistry.putActual(event);
    }
  }, myProject);
}
项目:intellij-ce-playground    文件:DomChildrenTest.java   
public void testUndefineCollectionChild() throws Throwable {
  final MyElement element = createElement("<a><child-element/><child-element/><child-element/></a>");
  final MyElement child1 = element.getChildElements().get(0);
  final MyElement child2 = element.getChildElements().get(1);
  final MyElement child3 = element.getChildElements().get(2);

  final List<XmlTag> oldChildren = new ArrayList<XmlTag>(Arrays.asList(element.getXmlTag().getSubTags()));

  assertTrue(child2.isValid());
  assertEquals(element, child2.getParent());

  WriteCommandAction.runWriteCommandAction(null, new Runnable() {
    @Override
    public void run() {
      child2.undefine();
      assertFalse(child2.isValid());

      oldChildren.remove(1);
      assertEquals(oldChildren, Arrays.asList(element.getXmlTag().getSubTags()));

      assertEquals(Arrays.asList(child1, child3), element.getChildElements());
      assertCached(child1, element.getXmlTag().findSubTags("child-element")[0]);
      assertCached(child3, element.getXmlTag().findSubTags("child-element")[1]);
    }
  });


  myCallRegistry.putExpected(new DomEvent(element, false));
  myCallRegistry.assertResultsAndClear();
}