Search in sources :

Example 41 with XmlNSDescriptor

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<>());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with XmlNSDescriptor

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));
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 43 with XmlNSDescriptor

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);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 44 with XmlNSDescriptor

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);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 45 with XmlNSDescriptor

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]);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)87 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)60 XmlTag (com.intellij.psi.xml.XmlTag)52 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)32 XmlFile (com.intellij.psi.xml.XmlFile)21 Nullable (org.jetbrains.annotations.Nullable)11 XmlDocument (com.intellij.psi.xml.XmlDocument)10 PsiElement (com.intellij.psi.PsiElement)5 XmlAttribute (com.intellij.psi.xml.XmlAttribute)5 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)5 XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)5 CachedValue (com.intellij.psi.util.CachedValue)3 NotNull (org.jetbrains.annotations.NotNull)3 FlexMxmlNSDescriptor (com.intellij.javascript.flex.mxml.schema.FlexMxmlNSDescriptor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 HtmlTag (com.intellij.psi.html.HtmlTag)2 PsiMetaData (com.intellij.psi.meta.PsiMetaData)2 PsiElementProcessor (com.intellij.psi.search.PsiElementProcessor)2 XmlElementDescriptorImpl (com.intellij.xml.impl.schema.XmlElementDescriptorImpl)2