Search in sources :

Example 16 with PomModelEvent

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

the class XmlTagImpl method setName.

@Override
public PsiElement setName(@NotNull final String name) 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() throws IncorrectOperationException {
            final String oldName = getName();
            final XmlTagImpl dummyTag = (XmlTagImpl) XmlElementFactory.getInstance(getProject()).createTagFromText(XmlTagUtil.composeTagText(name, "aa"));
            final XmlTagImpl tag = XmlTagImpl.this;
            final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(tag);
            ASTNode child = XmlChildRole.START_TAG_NAME_FINDER.findChild(tag);
            LOG.assertTrue(child != null, "It seems '" + name + "' is not a valid tag name");
            TreeElement tagElement = (TreeElement) XmlChildRole.START_TAG_NAME_FINDER.findChild(dummyTag);
            LOG.assertTrue(tagElement != null, "What's wrong with it? '" + name + "'");
            tag.replaceChild(child, ChangeUtil.copyElement(tagElement, charTableByTree));
            final ASTNode childByRole = XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(tag);
            if (childByRole != null) {
                final TreeElement treeElement = (TreeElement) XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(dummyTag);
                if (treeElement != null) {
                    tag.replaceChild(childByRole, ChangeUtil.copyElement(treeElement, charTableByTree));
                }
            }
            return XmlTagNameChangedImpl.createXmlTagNameChanged(model, tag, oldName);
        }
    });
    return this;
}
Also used : XmlAspect(com.intellij.pom.xml.XmlAspect) ASTNode(com.intellij.lang.ASTNode) PomModel(com.intellij.pom.PomModel) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PomModelEvent(com.intellij.pom.event.PomModelEvent) CharTable(com.intellij.util.CharTable)

Example 17 with PomModelEvent

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

the class XmlDocumentImpl method addInternal.

@Override
public TreeElement addInternal(final TreeElement first, final ASTNode last, final ASTNode anchor, final Boolean before) {
    final PomModel model = PomManager.getModel(getProject());
    final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
    final TreeElement[] holder = new TreeElement[1];
    try {
        model.runTransaction(new PomTransactionBase(this, aspect) {

            @Override
            public PomModelEvent runInner() {
                holder[0] = XmlDocumentImpl.super.addInternal(first, last, anchor, before);
                return XmlDocumentChangedImpl.createXmlDocumentChanged(model, XmlDocumentImpl.this);
            }
        });
    } catch (IncorrectOperationException ignored) {
    }
    return holder[0];
}
Also used : XmlAspect(com.intellij.pom.xml.XmlAspect) PomModel(com.intellij.pom.PomModel) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PomModelEvent(com.intellij.pom.event.PomModelEvent) IncorrectOperationException(com.intellij.util.IncorrectOperationException) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 18 with PomModelEvent

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

the class XmlDocumentImpl method replaceChildInternal.

@Override
public void replaceChildInternal(@NotNull final ASTNode child, @NotNull final TreeElement newElement) {
    final PomModel model = PomManager.getModel(getProject());
    final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
    try {
        model.runTransaction(new PomTransactionBase(this, aspect) {

            @Override
            public PomModelEvent runInner() {
                XmlDocumentImpl.super.replaceChildInternal(child, newElement);
                return XmlDocumentChangedImpl.createXmlDocumentChanged(model, XmlDocumentImpl.this);
            }
        });
    } catch (IncorrectOperationException ignored) {
    }
}
Also used : XmlAspect(com.intellij.pom.xml.XmlAspect) PomModel(com.intellij.pom.PomModel) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PomModelEvent(com.intellij.pom.event.PomModelEvent) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 19 with PomModelEvent

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

the class XmlTextChangedImpl method createXmlTextChanged.

public static PomModelEvent createXmlTextChanged(PomModel source, XmlText xmlText, String oldText) {
    final PomModelEvent event = new PomModelEvent(source);
    final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(source, PsiTreeUtil.getParentOfType(xmlText, XmlFile.class));
    xmlAspectChangeSet.add(new XmlTextChangedImpl(xmlText, oldText));
    event.registerChangeSet(source.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
    return event;
}
Also used : XmlAspectChangeSetImpl(com.intellij.pom.xml.impl.XmlAspectChangeSetImpl) XmlFile(com.intellij.psi.xml.XmlFile) XmlAspect(com.intellij.pom.xml.XmlAspect) PomModelEvent(com.intellij.pom.event.PomModelEvent)

Example 20 with PomModelEvent

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

the class XmlDocumentChangedImpl method createXmlDocumentChanged.

public static PomModelEvent createXmlDocumentChanged(PomModel source, XmlDocument document) {
    final PomModelEvent event = new PomModelEvent(source);
    XmlFile xmlFile = PsiTreeUtil.getParentOfType(document, XmlFile.class);
    final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(source, xmlFile);
    xmlAspectChangeSet.add(new XmlDocumentChangedImpl(document));
    event.registerChangeSet(source.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
    return event;
}
Also used : XmlAspectChangeSetImpl(com.intellij.pom.xml.impl.XmlAspectChangeSetImpl) XmlFile(com.intellij.psi.xml.XmlFile) XmlAspect(com.intellij.pom.xml.XmlAspect) 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