use of com.intellij.pom.PomTransaction 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);
}
}
}
Aggregations