Search in sources :

Example 16 with XmlAttributeDescriptor

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

the class TypeOrElementOrAttributeReference method resolveInner.

private PsiElement resolveInner() {
    final XmlTag tag = PsiTreeUtil.getContextOfType(myElement, XmlTag.class, false);
    if (tag == null)
        return PsiUtilCore.NULL_PSI_ELEMENT;
    String canonicalText = getCanonicalText();
    boolean[] redefined = new boolean[1];
    XmlNSDescriptorImpl nsDescriptor = getDescriptor(tag, canonicalText, redefined);
    if (myType != null && nsDescriptor != null && nsDescriptor.getTag() != null) {
        switch(myType) {
            case GroupReference:
                return nsDescriptor.findGroup(canonicalText);
            case AttributeGroupReference:
                return nsDescriptor.findAttributeGroup(canonicalText);
            case ElementReference:
                {
                    XmlElementDescriptor descriptor = nsDescriptor.getElementDescriptor(XmlUtil.findLocalNameByQualifiedName(canonicalText), getNamespace(tag, canonicalText), new HashSet<>(), true);
                    return descriptor != null ? descriptor.getDeclaration() : PsiUtilCore.NULL_PSI_ELEMENT;
                }
            case AttributeReference:
                {
                    //final String prefixByQualifiedName = XmlUtil.findPrefixByQualifiedName(canonicalText);
                    final String localNameByQualifiedName = XmlUtil.findLocalNameByQualifiedName(canonicalText);
                    XmlAttributeDescriptor descriptor = nsDescriptor.getAttribute(localNameByQualifiedName, getNamespace(tag, canonicalText), tag);
                    if (descriptor != null)
                        return descriptor.getDeclaration();
                    return PsiUtilCore.NULL_PSI_ELEMENT;
                }
            case TypeReference:
                {
                    TypeDescriptor typeDescriptor = redefined[0] ? nsDescriptor.findTypeDescriptor(XmlUtil.findLocalNameByQualifiedName(canonicalText), "") : nsDescriptor.getTypeDescriptor(canonicalText, tag);
                    if (typeDescriptor instanceof ComplexTypeDescriptor) {
                        return typeDescriptor.getDeclaration();
                    } else if (typeDescriptor != null) {
                        return myElement;
                    }
                }
        }
    }
    return PsiUtilCore.NULL_PSI_ELEMENT;
}
Also used : ComplexTypeDescriptor(com.intellij.xml.impl.schema.ComplexTypeDescriptor) TypeDescriptor(com.intellij.xml.impl.schema.TypeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) ComplexTypeDescriptor(com.intellij.xml.impl.schema.ComplexTypeDescriptor) XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) HashSet(java.util.HashSet)

Example 17 with XmlAttributeDescriptor

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

the class HtmlElementDescriptorImpl method collectAttributeDescriptorsMap.

// Read-only calculation
@Override
protected HashMap<String, XmlAttributeDescriptor> collectAttributeDescriptorsMap(final XmlTag context) {
    final HashMap<String, XmlAttributeDescriptor> hashMap = new HashMap<>();
    XmlAttributeDescriptor[] elementAttributeDescriptors = myDelegate.getAttributesDescriptors(context);
    for (final XmlAttributeDescriptor attributeDescriptor : elementAttributeDescriptors) {
        hashMap.put(attributeDescriptor.getName(), new HtmlAttributeDescriptorImpl(attributeDescriptor, myCaseSensitive));
    }
    return hashMap;
}
Also used : HashMap(java.util.HashMap) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor)

Example 18 with XmlAttributeDescriptor

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

the class XmlInsightTest method testAttributeDescriptor2.

public void testAttributeDescriptor2() throws Exception {
    XmlFile file = createFile("<root><a c='' a=''></a></root>");
    XmlNSDescriptor descriptor = createDescriptor(file);
    XmlTag rootTag = file.getDocument().getRootTag();
    XmlElementDescriptor element = descriptor.getElementDescriptor(rootTag);
    element = element.getElementsDescriptors(rootTag)[0];
    XmlAttributeDescriptor[] attributes = element.getAttributesDescriptors(rootTag);
    assertEquals("c", attributes[0].getName());
    assertTrue(attributes[0].isRequired());
    assertEquals("a", attributes[1].getName());
    assertTrue(attributes[1].isRequired());
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 19 with XmlAttributeDescriptor

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

the class XmlInsightTest method testAttributeDescriptor1.

public void testAttributeDescriptor1() throws Exception {
    XmlFile file = createFile("<root><a attr1=''></a><a attr2='' attr1=''></a></root>");
    XmlNSDescriptor descriptor = createDescriptor(file);
    XmlTag rootTag = file.getDocument().getRootTag();
    XmlElementDescriptor element = descriptor.getElementDescriptor(rootTag);
    element = element.getElementsDescriptors(rootTag)[0];
    XmlAttributeDescriptor[] attributes = element.getAttributesDescriptors(rootTag);
    assertEquals("attr1", attributes[0].getName());
    assertTrue(attributes[0].isRequired());
    assertEquals("attr2", attributes[1].getName());
    assertTrue(!attributes[1].isRequired());
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 20 with XmlAttributeDescriptor

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

the class XmlSchemaTest method testElementDescriptor10.

public void testElementDescriptor10() throws Exception {
    XmlNSDescriptor NSDescriptor = createDescriptor("<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<xsd:element name=\"purchaseOrder\" type=\"PurchaseOrderType\"/>" + "<xsd:complexType name=\"PurchaseOrderType\">" + "    <xsd:attributeGroup ref=\"ddd:bookAttributes\"/>" + "</xsd:complexType>" + "<xsd:attributeGroup name=\"bookAttributes\">" + "   <xsd:attribute name=\"isbn\" type=\"xs:string\" use=\"required\"/>" + "   <xsd:attribute name=\"available\" type=\"xs:string\"/>" + "</xsd:attributeGroup>" + "</xsd:schema>");
    final XmlTag tag = XmlTestUtil.tag("purchaseOrder", getProject());
    XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
    XmlAttributeDescriptor[] attributes = elementDescriptor.getAttributesDescriptors(tag);
    assertEquals(2, attributes.length);
    assertEquals("isbn", attributes[0].getName());
    assertEquals("available", attributes[1].getName());
    assertEquals("isbn", elementDescriptor.getAttributeDescriptor("isbn", tag).getName());
    assertNull(elementDescriptor.getAttributeDescriptor("xxx", tag));
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

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