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;
}
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;
}
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);
}
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);
}
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]);
}
Aggregations