Search in sources :

Example 1 with PomTransaction

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);
        }
    }
}
Also used : PomModelEvent(com.intellij.pom.event.PomModelEvent) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) CompoundRuntimeException(com.intellij.util.lang.CompoundRuntimeException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PomModelListener(com.intellij.pom.event.PomModelListener) PomModelAspect(com.intellij.pom.PomModelAspect) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PomTransaction(com.intellij.pom.PomTransaction) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 PomModelAspect (com.intellij.pom.PomModelAspect)1 PomTransaction (com.intellij.pom.PomTransaction)1 PomModelEvent (com.intellij.pom.event.PomModelEvent)1 PomModelListener (com.intellij.pom.event.PomModelListener)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 CompoundRuntimeException (com.intellij.util.lang.CompoundRuntimeException)1