use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class MavenPropertyPsiReference method processSchema.
@Nullable
private <T> T processSchema(String schema, SchemaProcessor<T> processor) {
VirtualFile file = MavenSchemaProvider.getSchemaFile(schema);
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
if (!(psiFile instanceof XmlFile))
return null;
XmlFile xmlFile = (XmlFile) psiFile;
XmlDocument document = xmlFile.getDocument();
XmlNSDescriptor desc = (XmlNSDescriptor) document.getMetaData();
XmlElementDescriptor[] descriptors = desc.getRootElementsDescriptors(document);
return doProcessSchema(descriptors, null, processor, new THashSet<>());
}
use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class XmlSchemaTest method testElementDescriptor9.
public void testElementDescriptor9() 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:sequence>" + " <xsd:group ref=\"ddd:mainBookElements\"/>" + " </xsd:sequence>" + "</xsd:complexType>" + "<xsd:group name=\"mainBookElements\">" + " <xsd:sequence>" + " <xsd:element name=\"title\" type=\"nameType\"/>" + " <xsd:element name=\"author\" type=\"nameType\"/>" + " </xsd:sequence>" + "</xsd:group>" + "</xsd:schema>");
XmlTag tag = XmlTestUtil.tag("purchaseOrder", getProject());
XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
XmlElementDescriptor[] elements = elementDescriptor.getElementsDescriptors(tag);
assertEquals(2, elements.length);
assertEquals("title", elements[0].getName());
assertEquals("author", elements[1].getName());
assertEquals("title", elementDescriptor.getElementDescriptor(XmlTestUtil.tag("title", getProject()), null).getName());
assertNull(elementDescriptor.getElementDescriptor(UNKNOWN_TAG, null));
}
use of com.intellij.xml.XmlNSDescriptor 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.XmlNSDescriptor 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.XmlNSDescriptor 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