Search in sources :

Example 11 with PomModelEvent

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);
        }
    }
}
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 12 with PomModelEvent

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);
}
Also used : PomModelEvent(com.intellij.pom.event.PomModelEvent)

Example 13 with PomModelEvent

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;
        }
    });
}
Also used : TreeAspect(com.intellij.pom.tree.TreeAspect) TreeChangeEvent(com.intellij.pom.tree.events.TreeChangeEvent) TreeChangeEventImpl(com.intellij.pom.tree.events.impl.TreeChangeEventImpl) PsiManager(com.intellij.psi.PsiManager) PomModel(com.intellij.pom.PomModel) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PomModelEvent(com.intellij.pom.event.PomModelEvent)

Example 14 with PomModelEvent

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));
        }
    });
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ThrowableRunnable(com.intellij.util.ThrowableRunnable) TextRange(com.intellij.openapi.util.TextRange) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PomModelEvent(com.intellij.pom.event.PomModelEvent) TreeAspectEvent(com.intellij.pom.tree.TreeAspectEvent) DiffLog(com.intellij.psi.impl.source.text.DiffLog) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with PomModelEvent

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);
        }
    });
}
Also used : XmlAspect(com.intellij.pom.xml.XmlAspect) ASTNode(com.intellij.lang.ASTNode) PomModel(com.intellij.pom.PomModel) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PomModelEvent(com.intellij.pom.event.PomModelEvent)

Aggregations

PomModelEvent (com.intellij.pom.event.PomModelEvent)21 XmlAspect (com.intellij.pom.xml.XmlAspect)17 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)13 PomModel (com.intellij.pom.PomModel)12 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9 ASTNode (com.intellij.lang.ASTNode)7 XmlAspectChangeSetImpl (com.intellij.pom.xml.impl.XmlAspectChangeSetImpl)7 XmlFile (com.intellij.psi.xml.XmlFile)5 TreeChangeEvent (com.intellij.pom.tree.events.TreeChangeEvent)2 IElementType (com.intellij.psi.tree.IElementType)2 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 TextRange (com.intellij.openapi.util.TextRange)1 PomModelAspect (com.intellij.pom.PomModelAspect)1 PomTransaction (com.intellij.pom.PomTransaction)1 PomModelListener (com.intellij.pom.event.PomModelListener)1 TreeAspect (com.intellij.pom.tree.TreeAspect)1 TreeAspectEvent (com.intellij.pom.tree.TreeAspectEvent)1 TreeChangeEventImpl (com.intellij.pom.tree.events.impl.TreeChangeEventImpl)1 XmlChangeSet (com.intellij.pom.xml.XmlChangeSet)1