Exemplo n.º 1
0
  public void deleteChildInternal(@NotNull final ASTNode child) {
    final PomModel model = PomManager.getModel(getProject());
    final XmlAspect aspect = model.getModelAspect(XmlAspect.class);

    if (child.getElementType() == XmlElementType.XML_ATTRIBUTE) {
      try {
        model.runTransaction(
            new PomTransactionBase(this, aspect) {
              public PomModelEvent runInner() {
                final String name = ((XmlAttribute) child).getName();
                XmlTagImpl.super.deleteChildInternal(child);
                return XmlAttributeSetImpl.createXmlAttributeSet(
                    model, XmlTagImpl.this, name, null);
              }
            });
      } catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    } else {
      final ASTNode treePrev = child.getTreePrev();
      final ASTNode treeNext = child.getTreeNext();
      XmlTagImpl.super.deleteChildInternal(child);
      if (treePrev != null
          && treeNext != null
          && treePrev.getElementType() == XmlElementType.XML_TEXT
          && treeNext.getElementType() == XmlElementType.XML_TEXT) {
        final XmlText prevText = (XmlText) treePrev.getPsi();
        final XmlText nextText = (XmlText) treeNext.getPsi();
        try {
          prevText.setValue(prevText.getValue() + nextText.getValue());
          nextText.delete();
        } catch (IncorrectOperationException e) {
          LOG.error(e);
        }
      }
    }
  }