Search in sources :

Example 11 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.

the class DomInvocationHandler method getAttributeChild.

@NotNull
final AttributeChildInvocationHandler getAttributeChild(final AttributeChildDescriptionImpl description) {
    final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(description.getXmlName());
    if (myStub != null && description.isStubbed()) {
        AttributeStub stub = myStub.getAttributeStub(description.getXmlName());
        StubParentStrategy strategy = StubParentStrategy.createAttributeStrategy(stub, myStub);
        return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, strategy, stub);
    }
    final XmlTag tag = getXmlTag();
    if (tag != null) {
        // TODO: this seems ugly
        String ns = evaluatedXmlName.getNamespace(tag, getFile());
        final XmlAttribute attribute = tag.getAttribute(description.getXmlName().getLocalName(), ns.equals(tag.getNamespace()) ? null : ns);
        if (attribute != null) {
            PsiUtilCore.ensureValid(attribute);
            AttributeChildInvocationHandler semElement = myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
            if (semElement == null) {
                final AttributeChildInvocationHandler take2 = myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
                throw new AssertionError("No DOM at XML. Parent=" + tag + "; attribute=" + attribute + "; second attempt=" + take2);
            }
            return semElement;
        }
    }
    return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, new VirtualDomParentStrategy(this), null);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) AttributeStub(com.intellij.util.xml.stubs.AttributeStub) StubParentStrategy(com.intellij.util.xml.stubs.StubParentStrategy) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.

the class AttributeChildInvocationHandler method setValue.

@Override
protected void setValue(@Nullable final String value) {
    final XmlTag tag = ensureTagExists();
    final String attributeName = getXmlElementName();
    final String namespace = getXmlApiCompatibleNamespace(getParentHandler());
    final String oldValue = StringUtil.unescapeXml(tag.getAttributeValue(attributeName, namespace));
    final String newValue = XmlStringUtil.escapeString(value);
    if (Comparing.equal(oldValue, newValue, true))
        return;
    getManager().runChange(() -> {
        try {
            XmlAttribute attribute = tag.setAttribute(attributeName, namespace, newValue);
            setXmlElement(attribute);
            getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, this);
        } catch (IncorrectOperationException e) {
            LOG.error(e);
        }
    });
    final DomElement proxy = getProxy();
    getManager().fireEvent(oldValue != null ? new DomEvent(proxy, false) : new DomEvent(proxy, true));
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) DomElement(com.intellij.util.xml.DomElement) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlTag(com.intellij.psi.xml.XmlTag) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 13 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.

the class XmlSchemaTagsProcessor method processTag.

private void processTag(XmlTag tag, @Nullable XmlTag context) {
    if (myVisited.contains(tag))
        return;
    myVisited.add(tag);
    if (!XmlNSDescriptorImpl.checkSchemaNamespace(tag)) {
        processTagWithSubTags(tag, context, null);
        return;
    }
    String tagName = tag.getLocalName();
    if (checkTagName(tagName, "element", "attribute")) {
        XmlAttribute ref = tag.getAttribute("ref");
        if (ref != null) {
            XmlTag resolved = resolveTagReference(ref);
            if (resolved != null) {
                tagStarted(resolved, resolved.getLocalName(), tag, tag);
            }
        } else {
            tagStarted(tag, tag.getLocalName(), context, null);
        }
    } else if (checkTagName(tagName, "group")) {
        String value = tag.getAttributeValue("ref");
        if (value != null) {
            XmlTag group = myNsDescriptor.findGroup(value);
            if (group == null)
                group = resolveTagReference(tag.getAttribute("ref"));
            processTagWithSubTags(group, tag, tag);
        }
    } else if (checkTagName(tagName, "attributeGroup")) {
        String ref = tag.getAttributeValue("ref");
        if (ref == null)
            return;
        XmlTag group;
        XmlTag parentTag = tag.getParentTag();
        assert parentTag != null;
        if (XmlNSDescriptorImpl.equalsToSchemaName(parentTag, "attributeGroup") && ref.equals(parentTag.getAttributeValue("name"))) {
            group = resolveTagReference(tag.getAttribute("ref"));
            if (group == null)
                group = myNsDescriptor.findAttributeGroup(ref);
        } else {
            group = myNsDescriptor.findAttributeGroup(ref);
            if (group == null)
                group = resolveTagReference(tag.getAttribute("ref"));
        }
        processTagWithSubTags(group, tag, null);
    } else if (checkTagName(tagName, "restriction", "extension")) {
        processTagWithSubTags(resolveTagReference(tag.getAttribute("base")), tag, null);
        processTagWithSubTags(tag, context, null);
    } else if (!checkTagName(tagName, myTagsToIgnore)) {
        processTagWithSubTags(tag, context, null);
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlTag(com.intellij.psi.xml.XmlTag)

Example 14 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.

the class XmlTagTreeElement method getLocationString.

@Override
public String getLocationString() {
    final StringBuilder buffer = new StringBuilder();
    final XmlTag element = getElement();
    assert element != null;
    String id = element.getAttributeValue(ID_ATTR_NAME);
    String usedAttrName = null;
    if (id == null) {
        id = element.getAttributeValue(NAME_ATTR_NAME);
        if (id != null) {
            usedAttrName = NAME_ATTR_NAME;
        }
    } else {
        usedAttrName = ID_ATTR_NAME;
    }
    id = toCanonicalForm(id);
    for (XmlAttribute attribute : element.getAttributes()) {
        if (buffer.length() != 0) {
            buffer.append(' ');
        }
        final String name = attribute.getName();
        if (usedAttrName != null && id != null && usedAttrName.equals(name)) {
            // we output this name in name
            continue;
        }
        buffer.append(name);
        buffer.append('=').append('"').append(attribute.getValue()).append('"');
    }
    return buffer.toString();
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlTag(com.intellij.psi.xml.XmlTag)

Example 15 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.

the class XmlAttributeValueImpl method updateText.

@Override
public PsiLanguageInjectionHost updateText(@NotNull String text) {
    try {
        final String quoteChar = getTextLength() > 0 ? getText().substring(0, 1) : "";
        String contents = StringUtil.containsAnyChar(quoteChar, "'\"") ? StringUtil.trimEnd(StringUtil.trimStart(text, quoteChar), quoteChar) : text;
        XmlAttribute newAttribute = XmlElementFactory.getInstance(getProject()).createAttribute("q", contents, this);
        XmlAttributeValue newValue = newAttribute.getValueElement();
        CheckUtil.checkWritable(this);
        replaceAllChildrenToChildrenOf(newValue.getNode());
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
    return this;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Aggregations

XmlAttribute (com.intellij.psi.xml.XmlAttribute)220 XmlTag (com.intellij.psi.xml.XmlTag)116 PsiElement (com.intellij.psi.PsiElement)60 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)57 NotNull (org.jetbrains.annotations.NotNull)44 XmlFile (com.intellij.psi.xml.XmlFile)37 Nullable (org.jetbrains.annotations.Nullable)27 Project (com.intellij.openapi.project.Project)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 TextRange (com.intellij.openapi.util.TextRange)18 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)18 ArrayList (java.util.ArrayList)18 PsiFile (com.intellij.psi.PsiFile)17 PsiReference (com.intellij.psi.PsiReference)17 IncorrectOperationException (com.intellij.util.IncorrectOperationException)10 DomElement (com.intellij.util.xml.DomElement)10 Result (com.intellij.openapi.application.Result)9 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)9 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)8 XmlElement (com.intellij.psi.xml.XmlElement)6