Search in sources :

Example 61 with XmlAttributeDescriptor

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

the class JavaFxColorReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    final XmlAttributeValue attributeValue = (XmlAttributeValue) element;
    final PsiElement parent = attributeValue.getParent();
    if (parent instanceof XmlAttribute) {
        final XmlAttributeDescriptor descriptor = ((XmlAttribute) parent).getDescriptor();
        if (descriptor instanceof JavaFxPropertyAttributeDescriptor) {
            final PsiElement declaration = descriptor.getDeclaration();
            final PsiClassType propertyClassType = JavaFxPsiUtil.getPropertyClassType(declaration);
            if (propertyClassType != null && InheritanceUtil.isInheritor(propertyClassType, JavaFxCommonNames.JAVAFX_SCENE_PAINT)) {
                return new PsiReference[] { new JavaFxColorReference(attributeValue) };
            }
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) JavaFxPropertyAttributeDescriptor(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyAttributeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with XmlAttributeDescriptor

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

the class DomCompletionContributor method isSchemaEnumerated.

public static boolean isSchemaEnumerated(final PsiElement element) {
    if (element instanceof XmlTag) {
        final XmlTag simpleContent = XmlUtil.getSchemaSimpleContent((XmlTag) element);
        if (simpleContent != null && XmlUtil.collectEnumerationValues(simpleContent, new HashSet<>())) {
            return true;
        }
    }
    if (element instanceof XmlAttributeValue) {
        final PsiElement parent = element.getParent();
        if (parent instanceof XmlAttribute) {
            final XmlAttributeDescriptor descriptor = ((XmlAttribute) parent).getDescriptor();
            if (descriptor != null && descriptor.isEnumerated()) {
                return true;
            }
            String[] enumeratedValues = XmlAttributeValueGetter.getEnumeratedValues((XmlAttribute) parent);
            if (enumeratedValues.length > 0) {
                String value = descriptor == null ? null : descriptor.getDefaultValue();
                if (value == null || enumeratedValues.length != 1 || !value.equals(enumeratedValues[0])) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) HashSet(com.intellij.util.containers.HashSet)

Example 63 with XmlAttributeDescriptor

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

the class XmlSchemaTest method testAttributeDescriptorProhibited.

public void testAttributeDescriptorProhibited() 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:attribute name=\"orderDate\" type=\"xsd:date\" use=\"prohibited\" />" + "</xsd:complexType>" + "</xsd:schema>");
    final XmlTag tag = XmlTestUtil.tag("purchaseOrder", getProject());
    XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
    XmlAttributeDescriptor[] attributes = elementDescriptor.getAttributesDescriptors(tag);
    assertEquals(0, attributes.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 64 with XmlAttributeDescriptor

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

the class XmlSchemaTest method testElementDescriptor2.

public void testElementDescriptor2() throws Exception {
    XmlNSDescriptor NSDescriptor = createDescriptor("<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<xsd:element name=\"comment\" type=\"xsd:string\"/>" + "</xsd:schema>");
    XmlTag tag = XmlTestUtil.tag("comment", getProject());
    XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
    XmlElementDescriptor[] elements = elementDescriptor.getElementsDescriptors(tag);
    assertEquals(0, elements.length);
    XmlAttributeDescriptor[] descriptors = elementDescriptor.getAttributesDescriptors(tag);
    assertEquals(0, descriptors.length);
    assertEquals(elementDescriptor.getContentType(), XmlElementDescriptor.CONTENT_TYPE_MIXED);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 65 with XmlAttributeDescriptor

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

the class XmlDtdTest method testAttributeDescriptor5.

public void testAttributeDescriptor5() throws Exception {
    XmlNSDescriptor NSDescriptor = createDescriptor("<!ELEMENT toc ANY> <!ATTLIST toc remote (0|1|2) #REQUIRED>");
    final XmlTag tag = tag("toc");
    XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
    XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor("remote", tag);
    assertTrue(attributeDescriptor.isRequired());
    assertTrue(!attributeDescriptor.isFixed());
    assertTrue(attributeDescriptor.isEnumerated());
    assertNull(attributeDescriptor.getDefaultValue());
    String[] values = attributeDescriptor.getEnumeratedValues();
    assertEquals(3, values.length);
    assertEquals("0", values[0]);
    assertEquals("1", values[1]);
    assertEquals("2", values[2]);
}
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