use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.
the class XmlTagImpl method deleteChildInternal.
@Override
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) {
@Override
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();
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();
final String newValue = prevText.getValue() + nextText.getValue();
// merging two XmlText-s should be done in one transaction to preserve smart pointers
ChangeUtil.prepareAndRunChangeAction(new ChangeUtil.ChangeAction() {
@Override
public void makeChange(TreeChangeEvent destinationTreeChange) {
PsiElement anchor = prevText.getPrevSibling();
prevText.delete();
nextText.delete();
XmlText text = (XmlText) addAfter(XmlElementFactory.getInstance(getProject()).createDisplayText("x"), anchor);
text.setValue(newValue);
}
}, this);
}
}
}
use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.
the class XmlTextImpl method createEvent.
private PomModelEvent createEvent(final XmlChange... events) {
final PomModelEvent event = new PomModelEvent(PomManager.getModel(getProject()));
final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(PomManager.getModel(getProject()), (XmlFile) getContainingFile());
for (XmlChange xmlChange : events) {
xmlAspectChangeSet.add(xmlChange);
}
event.registerChangeSet(PomManager.getModel(getProject()).getModelAspect(XmlAspect.class), xmlAspectChangeSet);
return event;
}
use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.
the class XmlDocumentImpl method deleteChildInternal.
@Override
public void deleteChildInternal(@NotNull final ASTNode child) {
final PomModel model = PomManager.getModel(getProject());
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
try {
model.runTransaction(new PomTransactionBase(this, aspect) {
@Override
public PomModelEvent runInner() {
XmlDocumentImpl.super.deleteChildInternal(child);
return XmlDocumentChangedImpl.createXmlDocumentChanged(model, XmlDocumentImpl.this);
}
});
} catch (IncorrectOperationException ignored) {
}
}
use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.
the class XmlAttributeSetImpl method createXmlAttributeSet.
public static PomModelEvent createXmlAttributeSet(PomModel model, XmlTag xmlTag, String name, String value) {
final PomModelEvent event = new PomModelEvent(model);
final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(model, PsiTreeUtil.getParentOfType(xmlTag, XmlFile.class));
xmlAspectChangeSet.add(new XmlAttributeSetImpl(xmlTag, name, value));
event.registerChangeSet(model.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
return event;
}
use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.
the class XmlTagChildChangedImpl method createXmlTagChildChanged.
public static PomModelEvent createXmlTagChildChanged(PomModel source, XmlTag context, XmlTagChild treeElement) {
final PomModelEvent event = new PomModelEvent(source);
final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(source, PsiTreeUtil.getParentOfType(context, XmlFile.class));
xmlAspectChangeSet.add(new XmlTagChildChangedImpl(context, treeElement));
event.registerChangeSet(source.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
return event;
}
Aggregations