use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.
the class PomModelImpl method runTransaction.
@Override
public void runTransaction(@NotNull PomTransaction transaction) throws IncorrectOperationException {
if (!isAllowPsiModification()) {
throw new IncorrectOperationException("Must not modify PSI inside save listener");
}
synchronized (PsiLock.LOCK) {
List<Throwable> throwables = new ArrayList<>(0);
final PomModelAspect aspect = transaction.getTransactionAspect();
startTransaction(transaction);
try {
DebugUtil.startPsiModification(null);
myBlockedAspects.push(Pair.create(aspect, transaction));
final PomModelEvent event;
try {
transaction.run();
event = transaction.getAccumulatedEvent();
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
LOG.error(e);
return;
} finally {
myBlockedAspects.pop();
}
final Pair<PomModelAspect, PomTransaction> block = getBlockingTransaction(aspect, transaction);
if (block != null) {
final PomModelEvent currentEvent = block.getSecond().getAccumulatedEvent();
currentEvent.merge(event);
return;
}
{
// update
final Set<PomModelAspect> changedAspects = event.getChangedAspects();
final Collection<PomModelAspect> dependants = new LinkedHashSet<>();
for (final PomModelAspect pomModelAspect : changedAspects) {
dependants.addAll(getAllDependants(pomModelAspect));
}
for (final PomModelAspect modelAspect : dependants) {
if (!changedAspects.contains(modelAspect)) {
modelAspect.update(event);
}
}
}
for (final PomModelListener listener : myListeners) {
final Set<PomModelAspect> changedAspects = event.getChangedAspects();
for (PomModelAspect modelAspect : changedAspects) {
if (listener.isAspectChangeInteresting(modelAspect)) {
listener.modelChanged(event);
break;
}
}
}
} catch (ProcessCanceledException e) {
throw e;
} catch (Throwable t) {
throwables.add(t);
} finally {
try {
commitTransaction(transaction);
} catch (ProcessCanceledException e) {
throw e;
} catch (Throwable t) {
throwables.add(t);
} finally {
DebugUtil.finishPsiModification();
}
if (!throwables.isEmpty())
CompoundRuntimeException.throwIfNotEmpty(throwables);
}
}
}
use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.
the class PomTransactionBase method run.
@Override
public void run() throws IncorrectOperationException {
// override accumulated event because transaction should construct full model event in its aspect
final PomModelEvent event = runInner();
if (event == null) {
// in case of null event aspect change set supposed to be rebuild by low level events
myAccumulatedEvent.registerChangeSet(myAspect, null);
return;
}
myAccumulatedEvent.merge(event);
}
use of com.intellij.pom.event.PomModelEvent 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.event.PomModelEvent 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.event.PomModelEvent 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