use of com.intellij.pom.impl.PomTransactionBase 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.impl.PomTransactionBase 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.impl.PomTransactionBase in project intellij-community by JetBrains.
the class PomModelImpl method reparseFile.
@Nullable
private Runnable reparseFile(@NotNull final PsiFile file, @NotNull FileElement treeElement, @NotNull CharSequence newText) {
TextRange changedPsiRange = DocumentCommitThread.getChangedPsiRange(file, treeElement, newText);
if (changedPsiRange == null)
return null;
Runnable reparseLeaf = tryReparseOneLeaf(treeElement, newText, changedPsiRange);
if (reparseLeaf != null)
return reparseLeaf;
final DiffLog log = BlockSupport.getInstance(myProject).reparseRange(file, treeElement, changedPsiRange, newText, new EmptyProgressIndicator(), treeElement.getText());
return () -> runTransaction(new PomTransactionBase(file, getModelAspect(TreeAspect.class)) {
@Nullable
@Override
public PomModelEvent runInner() throws IncorrectOperationException {
return new TreeAspectEvent(PomModelImpl.this, log.performActualPsiChange(file));
}
});
}
use of com.intellij.pom.impl.PomTransactionBase in project intellij-community by JetBrains.
the class ChangeUtil method prepareAndRunChangeAction.
public static void prepareAndRunChangeAction(final ChangeAction action, final TreeElement changedElement) {
final FileElement changedFile = TreeUtil.getFileElement(changedElement);
final PsiManager manager = changedFile.getManager();
final PomModel model = PomManager.getModel(manager.getProject());
final TreeAspect treeAspect = model.getModelAspect(TreeAspect.class);
model.runTransaction(new PomTransactionBase(changedElement.getPsi(), treeAspect) {
@Override
public PomModelEvent runInner() {
final PomModelEvent event = new PomModelEvent(model);
final TreeChangeEvent destinationTreeChange = new TreeChangeEventImpl(treeAspect, changedFile);
event.registerChangeSet(treeAspect, destinationTreeChange);
action.makeChange(destinationTreeChange);
changedElement.clearCaches();
if (changedElement instanceof CompositeElement) {
((CompositeElement) changedElement).subtreeChanged();
}
return event;
}
});
}
use of com.intellij.pom.impl.PomTransactionBase in project intellij-community by JetBrains.
the class XmlTextImpl method doSetValue.
public void doSetValue(final String s, final XmlPsiPolicy policy) throws IncorrectOperationException {
final PomModel model = PomManager.getModel(getProject());
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
model.runTransaction(new PomTransactionBase(this, aspect) {
@Override
public PomModelEvent runInner() {
final String oldText = getText();
final ASTNode firstEncodedElement = policy.encodeXmlTextContents(s, XmlTextImpl.this);
if (firstEncodedElement == null) {
delete();
} else {
replaceAllChildrenToChildrenOf(firstEncodedElement.getTreeParent());
}
clearCaches();
return XmlTextChangedImpl.createXmlTextChanged(model, XmlTextImpl.this, oldText);
}
});
}
Aggregations