Search in sources :

Example 1 with XmlAttributeSetImpl

use of com.intellij.pom.xml.impl.events.XmlAttributeSetImpl in project intellij-community by JetBrains.

the class XmlAttributeImpl method setName.

@Override
public PsiElement setName(@NotNull final String nameText) throws IncorrectOperationException {
    final ASTNode name = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(this);
    final String oldName = name.getText();
    final PomModel model = PomManager.getModel(getProject());
    final XmlAttribute attribute = XmlElementFactory.getInstance(getProject()).createAttribute(nameText, "", this);
    final ASTNode newName = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild((ASTNode) attribute);
    final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
    model.runTransaction(new PomTransactionBase(getParent(), aspect) {

        @Override
        public PomModelEvent runInner() {
            final PomModelEvent event = new PomModelEvent(model);
            PsiFile file = getContainingFile();
            XmlChangeSet xmlAspectChangeSet = new XmlAspectChangeSetImpl(model, file instanceof XmlFile ? (XmlFile) file : null);
            xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), oldName, null));
            xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), nameText, getValue()));
            event.registerChangeSet(model.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
            CodeEditUtil.replaceChild(XmlAttributeImpl.this, name, newName);
            return event;
        }
    });
    return this;
}
Also used : XmlAttributeSetImpl(com.intellij.pom.xml.impl.events.XmlAttributeSetImpl) XmlChangeSet(com.intellij.pom.xml.XmlChangeSet) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PomModelEvent(com.intellij.pom.event.PomModelEvent) XmlAspectChangeSetImpl(com.intellij.pom.xml.impl.XmlAspectChangeSetImpl) XmlAspect(com.intellij.pom.xml.XmlAspect) ASTNode(com.intellij.lang.ASTNode) PomModel(com.intellij.pom.PomModel)

Aggregations

ASTNode (com.intellij.lang.ASTNode)1 PomModel (com.intellij.pom.PomModel)1 PomModelEvent (com.intellij.pom.event.PomModelEvent)1 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)1 XmlAspect (com.intellij.pom.xml.XmlAspect)1 XmlChangeSet (com.intellij.pom.xml.XmlChangeSet)1 XmlAspectChangeSetImpl (com.intellij.pom.xml.impl.XmlAspectChangeSetImpl)1 XmlAttributeSetImpl (com.intellij.pom.xml.impl.events.XmlAttributeSetImpl)1