Search in sources :

Example 76 with XmlAttributeDescriptor

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

the class XmlDtdTest method testEntityDecl5.

public void testEntityDecl5() throws Exception {
    XmlNSDescriptor NSDescriptor = createDescriptor("<!ENTITY % boolean \"true | false\" > <!ELEMENT foo EMPTY> <!ATTLIST foo someBoolean (%boolean;) \"true\" someString CDATA #IMPLIED >");
    final XmlTag tag = tag("foo");
    final XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
    final XmlAttributeDescriptor[] attributes = elementDescriptor.getAttributesDescriptors(tag);
    assertEquals(2, attributes.length);
    assertEquals("someBoolean", attributes[0].getName());
    assertEquals("someString", attributes[1].getName());
    assertTrue(attributes[0].isEnumerated());
    assertEquals(2, attributes[0].getEnumeratedValues().length);
    assertEquals("true", attributes[0].getEnumeratedValues()[0]);
    assertEquals("false", attributes[0].getEnumeratedValues()[1]);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 77 with XmlAttributeDescriptor

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

the class XmlDtdTest method testElementDescriptor3.

public void testElementDescriptor3() throws Exception {
    XmlNSDescriptor NSDescriptor = createDescriptor("<!ELEMENT principals ANY><!ATTLIST principals path CDATA #IMPLIED smtp-host CDATA #REQUIRED>" + "<!ATTLIST principals address CDATA #IMPLIED>");
    final XmlTag tag = tag("principals");
    XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
    XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor("path", tag);
    assertNotNull(attributeDescriptor);
    attributeDescriptor = elementDescriptor.getAttributeDescriptor("xxx", tag);
    assertNull(attributeDescriptor);
    attributeDescriptor = elementDescriptor.getAttributeDescriptor("smtp-host", tag);
    assertNotNull(attributeDescriptor);
    attributeDescriptor = elementDescriptor.getAttributeDescriptor("address", tag);
    assertNotNull(attributeDescriptor);
    XmlAttributeDescriptor[] descriptors = elementDescriptor.getAttributesDescriptors(tag);
    assertEquals("path", descriptors[0].getName());
    assertEquals("smtp-host", descriptors[1].getName());
    assertEquals("address", descriptors[2].getName());
    assertEquals(3, descriptors.length);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 78 with XmlAttributeDescriptor

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

the class XmlElementDescriptorImpl method collectAttributeDescriptors.

// Read-only calculation
@Override
protected final XmlAttributeDescriptor[] collectAttributeDescriptors(final XmlTag context) {
    final List<XmlAttributeDescriptor> result = new SmartList<>();
    for (XmlAttlistDecl attlistDecl : findAttlistDeclarations(getName())) {
        for (XmlAttributeDecl attributeDecl : attlistDecl.getAttributeDecls()) {
            final PsiMetaData psiMetaData = attributeDecl.getMetaData();
            assert psiMetaData instanceof XmlAttributeDescriptor;
            result.add((XmlAttributeDescriptor) psiMetaData);
        }
    }
    return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) SmartList(com.intellij.util.SmartList)

Example 79 with XmlAttributeDescriptor

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

the class XmlAttributeDescriptorImpl method shouldBeQualified.

private boolean shouldBeQualified(String targetNs, XmlTag contextTag) {
    boolean attributeShouldBeQualified = false;
    String contextNs = contextTag.getNamespace();
    if (!contextNs.equals(targetNs)) {
        final XmlElementDescriptor xmlElementDescriptor = contextTag.getDescriptor();
        if (xmlElementDescriptor instanceof XmlElementDescriptorImpl) {
            final XmlElementDescriptorImpl elementDescriptor = (XmlElementDescriptorImpl) xmlElementDescriptor;
            final TypeDescriptor type = elementDescriptor.getType();
            if (type instanceof ComplexTypeDescriptor) {
                final ComplexTypeDescriptor typeDescriptor = (ComplexTypeDescriptor) type;
                if (myReferenceName != null) {
                    return myReferenceName.indexOf(':') != 0;
                }
                XmlAttributeDescriptor[] attributes = ((ComplexTypeDescriptor) type).getAttributes(contextTag);
                if (ArrayUtil.contains(this, attributes)) {
                    return false;
                }
                attributeShouldBeQualified = typeDescriptor.canContainAttribute(targetNs, null) != ComplexTypeDescriptor.CanContainAttributeType.CanNotContain;
            }
            if (!attributeShouldBeQualified && contextNs.length() == 0 && targetNs.length() > 0) {
                attributeShouldBeQualified = !targetNs.equals(elementDescriptor.getNamespace());
            }
        }
    }
    return attributeShouldBeQualified;
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 80 with XmlAttributeDescriptor

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

the class XmlAttributeImpl method getDescriptor.

@Override
@Nullable
public XmlAttributeDescriptor getDescriptor() {
    final PsiElement parentElement = getParent();
    // e.g. XmlDecl or PI
    if (parentElement == null)
        return null;
    final XmlTag tag = (XmlTag) parentElement;
    final XmlElementDescriptor descr = tag.getDescriptor();
    if (descr == null)
        return null;
    final XmlAttributeDescriptor attributeDescr = descr.getAttributeDescriptor(this);
    return attributeDescr == null ? descr.getAttributeDescriptor(getName(), tag) : attributeDescr;
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) 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