Search in sources :

Example 81 with XmlAttribute

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

the class MxmlTagNameReference method insertNamespaceDeclaration.

public static void insertNamespaceDeclaration(@NotNull final XmlTag tag, @NotNull final String namespace, @NotNull final String prefix) {
    final XmlAttribute[] attributes = tag.getAttributes();
    XmlAttribute anchor = null;
    for (final XmlAttribute attribute : attributes) {
        final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
        if (attribute.isNamespaceDeclaration() || (descriptor != null && descriptor.isRequired())) {
            anchor = attribute;
        } else {
            break;
        }
    }
    @NonNls final String qname = "xmlns" + (prefix.length() > 0 ? ":" + prefix : "");
    final XmlAttribute attribute = XmlElementFactory.getInstance(tag.getProject()).createXmlAttribute(qname, namespace);
    if (anchor == null) {
        tag.add(attribute);
    } else {
        tag.addAfter(attribute, anchor);
    }
    CodeStyleManager.getInstance(tag.getProject()).reformat(tag);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor)

Example 82 with XmlAttribute

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

the class DeletionHandler method transfer.

private void transfer(NlComponent deleted, NlComponent target, ConstraintType targetType, int depth) {
    if (depth == 20) {
        // the cycle detection code
        return;
    }
    assert myDeleted.contains(deleted);
    for (XmlAttribute attribute : deleted.getTag().getAttributes()) {
        String name = attribute.getLocalName();
        ConstraintType type = ConstraintType.fromAttribute(name);
        if (type == null) {
            continue;
        }
        ConstraintType transfer = getCompatibleConstraint(type, targetType);
        if (transfer != null) {
            String id = getId(attribute);
            if (id != null) {
                if (myDeletedIds.contains(id)) {
                    NlComponent nextDeleted = myNodeMap.get(id);
                    if (nextDeleted != null) {
                        // Points to another deleted node: recurse
                        transfer(nextDeleted, target, targetType, depth + 1);
                    }
                } else {
                    // Found an undeleted node destination: point to it directly.
                    // Note that we're using the
                    target.setAttribute(ANDROID_URI, transfer.name, attribute.getValue());
                }
            } else {
                // Pointing to parent or center etc (non-id ref): replicate this on the target
                target.setAttribute(ANDROID_URI, name, attribute.getValue());
            }
        }
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 83 with XmlAttribute

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

the class DeletionHandler method updateConstraints.

/**
   * Updates the constraints in the layout to handle deletion of a set of
   * nodes. This ensures that any constraints pointing to one of the deleted
   * nodes are changed properly to point to a non-deleted node with similar
   * constraints.
   */
public void updateConstraints() {
    if (myChildren.size() == myDeleted.size()) {
        // Deleting everything: Nothing to be done
        return;
    }
    for (NlComponent child : myChildren) {
        if (myDeleted.contains(child)) {
            continue;
        }
        for (XmlAttribute attribute : child.getTag().getAttributes()) {
            String id = getId(attribute);
            if (id != null) {
                if (myDeletedIds.contains(id)) {
                    // Unset this reference to a deleted widget. It might be
                    // replaced if the pointed to node points to some other node
                    // on the same side, but it may use a different constraint name,
                    // or have none at all (e.g. parent).
                    String name = attribute.getLocalName();
                    attribute.delete();
                    NlComponent deleted = myNodeMap.get(id);
                    if (deleted != null) {
                        ConstraintType type = ConstraintType.fromAttribute(name);
                        if (type != null) {
                            transfer(deleted, child, type, 0);
                        }
                    }
                }
            }
        }
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 84 with XmlAttribute

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

the class AngularJSAttributeDescriptorsProvider method getAttributeDescriptor.

@Nullable
@Override
public XmlAttributeDescriptor getAttributeDescriptor(final String attrName, XmlTag xmlTag) {
    if (xmlTag != null) {
        final Project project = xmlTag.getProject();
        final String attributeName = DirectiveUtil.normalizeAttributeName(attrName);
        PsiElement declaration = applicableDirective(project, attributeName, xmlTag, AngularDirectivesDocIndex.KEY);
        if (declaration == PsiUtilCore.NULL_PSI_ELEMENT) {
            declaration = applicableDirective(project, attributeName, xmlTag, AngularDirectivesIndex.KEY);
        }
        if (isApplicable(declaration)) {
            return createDescriptor(project, attributeName, declaration);
        }
        if (!AngularIndexUtil.hasAngularJS2(project))
            return null;
        for (XmlAttribute attribute : xmlTag.getAttributes()) {
            String name = attribute.getName();
            if (isAngular2Attribute(name, project) || name.equals(attrName))
                continue;
            declaration = applicableDirective(project, name, xmlTag, AngularDirectivesIndex.KEY);
            if (isApplicable(declaration)) {
                for (XmlAttributeDescriptor binding : AngularAttributeDescriptor.getFieldBasedDescriptors((JSImplicitElement) declaration)) {
                    if (binding.getName().equals(attrName)) {
                        return binding;
                    }
                }
            }
        }
        if (AngularAttributesRegistry.isBindingAttribute(attrName, project)) {
            return new AngularBindingDescriptor(xmlTag, attrName);
        }
        if (AngularAttributesRegistry.isEventAttribute(attrName, project)) {
            return new AngularEventHandlerDescriptor(xmlTag, attrName);
        }
        return getAngular2Descriptor(attrName, project);
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 85 with XmlAttribute

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

the class ActionScriptCustomIndexer method processXmlTag.

@Override
protected JSQualifiedName processXmlTag(XmlTag element) {
    final XmlAttribute idAttribute = element.getAttribute("id");
    final String id = idAttribute == null ? null : idAttribute.getValue();
    if (idAttribute != null && id != null) {
        final JSImplicitElementImpl.Builder builder = new JSImplicitElementImpl.Builder(id, null).setType(JSImplicitElement.Type.Tag);
        addImplicitElement(idAttribute, builder);
    }
    return myNamespaces.peek();
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) JSImplicitElementImpl(com.intellij.lang.javascript.psi.stubs.impl.JSImplicitElementImpl)

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