Search in sources :

Example 36 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor in project android by JetBrains.

the class PropertyTestCase method createFrom.

@NotNull
protected NlPropertyItem createFrom(@NotNull NlComponent component, @NotNull String attributeName) {
    List<NlComponent> components = ImmutableList.of(component);
    XmlAttributeDescriptor descriptor = getDescriptor(component, attributeName);
    assertThat(descriptor).isNotNull();
    AttributeDefinition definition = getDefinition(component, descriptor);
    String namespace = getNamespace(component, descriptor);
    return NlPropertyItem.create(components, descriptor, namespace, definition);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) NamespaceAwareXmlAttributeDescriptor(com.intellij.xml.NamespaceAwareXmlAttributeDescriptor) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor in project android by JetBrains.

the class NlPropertyItemTest method testCreateWithoutSpecifyingNamespace.

public void testCreateWithoutSpecifyingNamespace() {
    XmlAttributeDescriptor descriptor = getDescriptor(myTextView, ATTR_TEXT);
    assertThat(descriptor).isNotNull();
    NlPropertyItem item = NlPropertyItem.create(ImmutableList.of(myTextView), descriptor, null, getDefinition(myTextView, descriptor));
    assertThat(item).isNotInstanceOf(NlFlagPropertyItem.class);
    assertThat(item).isNotInstanceOf(NlIdPropertyItem.class);
    assertThat(item.getName()).isEqualTo(ATTR_TEXT);
    assertThat(item.getNamespace()).isEqualTo(ANDROID_URI);
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor)

Example 38 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor in project android by JetBrains.

the class NlPropertyItemTest method testSameDefinition.

public void testSameDefinition() {
    NlPropertyItem text = createFrom(myTextView, ATTR_TEXT);
    NlPropertyItem gravity = createFrom(myTextView, ATTR_GRAVITY);
    XmlAttributeDescriptor gravityDescriptor = getDescriptor(myTextView, ATTR_GRAVITY);
    assertThat(gravityDescriptor).isNotNull();
    assertThat(text.sameDefinition(text)).isTrue();
    assertThat(text.sameDefinition(new NlPropertyItem(ImmutableList.of(myTextView), ANDROID_URI, text.getDefinition()))).isTrue();
    assertThat(text.sameDefinition(new NlPropertyItem(ImmutableList.of(myTextView), TOOLS_URI, text.getDefinition()))).isFalse();
    assertThat(text.sameDefinition(new NlPropertyItem(ImmutableList.of(myTextView), ANDROID_URI, gravity.getDefinition()))).isFalse();
    assertThat(text.sameDefinition(new NlPropertyItem(ImmutableList.of(myTextView), gravityDescriptor, TOOLS_URI, text.getDefinition()))).isFalse();
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor)

Example 39 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor 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 40 with XmlAttributeDescriptor

use of com.intellij.xml.XmlAttributeDescriptor 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)

Aggregations

XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)89 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)54 XmlTag (com.intellij.psi.xml.XmlTag)46 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)32 XmlAttribute (com.intellij.psi.xml.XmlAttribute)18 NotNull (org.jetbrains.annotations.NotNull)11 PsiElement (com.intellij.psi.PsiElement)10 ArrayList (java.util.ArrayList)8 XmlFile (com.intellij.psi.xml.XmlFile)7 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)6 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)6 Nullable (org.jetbrains.annotations.Nullable)6 Project (com.intellij.openapi.project.Project)5 HtmlTag (com.intellij.psi.html.HtmlTag)5 NamespaceAwareXmlAttributeDescriptor (com.intellij.xml.NamespaceAwareXmlAttributeDescriptor)5 AnyXmlAttributeDescriptor (com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor)5 JavaFxPropertyAttributeDescriptor (org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyAttributeDescriptor)5 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)3 PsiReference (com.intellij.psi.PsiReference)3 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)2