Search in sources :

Example 1 with PomModelAspect

use of com.intellij.pom.PomModelAspect 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)

Example 2 with PomModelAspect

use of com.intellij.pom.PomModelAspect in project intellij-community by JetBrains.

the class PomModelImpl method registerAspect.

@Override
public void registerAspect(@NotNull Class<? extends PomModelAspect> aClass, @NotNull PomModelAspect aspect, @NotNull Set<PomModelAspect> dependencies) {
    myAspects.put(aClass, aspect);
    final Iterator<PomModelAspect> iterator = dependencies.iterator();
    final List<PomModelAspect> deps = new ArrayList<>();
    // todo: reorder dependencies
    while (iterator.hasNext()) {
        final PomModelAspect depend = iterator.next();
        deps.addAll(getAllDependencies(depend));
    }
    // add self to block same aspect transactions from event processing and update
    deps.add(aspect);
    for (final PomModelAspect pomModelAspect : deps) {
        final List<PomModelAspect> pomModelAspects = myInvertedIncidence.get(pomModelAspect);
        if (pomModelAspects != null) {
            pomModelAspects.add(aspect);
        } else {
            myInvertedIncidence.put(pomModelAspect, new ArrayList<>(Collections.singletonList(aspect)));
        }
    }
    myIncidence.put(aspect, deps);
}
Also used : PomModelAspect(com.intellij.pom.PomModelAspect)

Example 3 with PomModelAspect

use of com.intellij.pom.PomModelAspect in project intellij-community by JetBrains.

the class PomModelEvent method merge.

public void merge(@NotNull PomModelEvent event) {
    if (event.myChangeSets == null)
        return;
    if (myChangeSets == null) {
        myChangeSets = new HashMap<>(event.myChangeSets);
        return;
    }
    for (final Map.Entry<PomModelAspect, PomChangeSet> entry : event.myChangeSets.entrySet()) {
        final PomModelAspect aspect = entry.getKey();
        final PomChangeSet pomChangeSet = myChangeSets.get(aspect);
        if (pomChangeSet != null) {
            pomChangeSet.merge(entry.getValue());
        } else {
            myChangeSets.put(aspect, entry.getValue());
        }
    }
}
Also used : PomModelAspect(com.intellij.pom.PomModelAspect)

Aggregations

PomModelAspect (com.intellij.pom.PomModelAspect)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)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