Search in sources :

Example 66 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor 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 67 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor 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 68 with XmlNSDescriptor

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

the class XmlDtdTest method testDocumentDescriptor1.

public void testDocumentDescriptor1() throws Exception {
    XmlNSDescriptor NSDescriptor = createDescriptor("<!ELEMENT principals (#PCDATA)><!ELEMENT data-sources (#PCDATA)>");
    XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag("principals"));
    assertNotNull(elementDescriptor);
    elementDescriptor = NSDescriptor.getElementDescriptor(tag("data-sources"));
    assertNotNull(elementDescriptor);
    elementDescriptor = NSDescriptor.getElementDescriptor(tag("xxx"));
    assertNull(elementDescriptor);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 69 with XmlNSDescriptor

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

the class XmlDtdTest method testElementDescriptor4.

public void testElementDescriptor4() throws Exception {
    XmlNSDescriptor NSDescriptor = createDescriptor("<!ELEMENT orion-application (ejb-module*, persistence?, namespace-access)>" + "<!ELEMENT ejb-module ANY>" + "<!ELEMENT persistence ANY>" + "<!ELEMENT namespace-access ANY>");
    XmlTag documentTag = tag("orion-application");
    XmlElementDescriptorImpl elementDescriptor = (XmlElementDescriptorImpl) NSDescriptor.getElementDescriptor(documentTag);
    XmlElementDescriptor[] elements = elementDescriptor.getElementsDescriptors(documentTag);
    assertEquals(3, elements.length);
    assertEquals("ejb-module", elements[0].getName());
    assertEquals("persistence", elements[1].getName());
    assertEquals("namespace-access", elements[2].getName());
    elements = elements[0].getElementsDescriptors(documentTag);
    assertEquals(4, elements.length);
    assertEquals("orion-application", elements[0].getName());
    assertEquals("ejb-module", elements[1].getName());
    assertEquals("persistence", elements[2].getName());
    assertEquals("namespace-access", elements[3].getName());
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptorImpl(com.intellij.xml.impl.dtd.XmlElementDescriptorImpl) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 70 with XmlNSDescriptor

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

the class URLReference method resolve.

@Override
@Nullable
public PsiElement resolve() {
    myIncorrectResourceMapped = false;
    final String canonicalText = getCanonicalText();
    if (canonicalText.isEmpty()) {
        final XmlAttribute attr = PsiTreeUtil.getParentOfType(getElement(), XmlAttribute.class);
        if (attr != null && attr.isNamespaceDeclaration() && attr.getNamespacePrefix().isEmpty() || ExternalResourceManagerEx.getInstanceEx().isIgnoredResource(canonicalText)) {
            // of there being no default namespace
            return myElement;
        }
        return null;
    }
    if (ExternalResourceManagerEx.getInstanceEx().isIgnoredResource(canonicalText))
        return myElement;
    final XmlTag tag = PsiTreeUtil.getParentOfType(myElement, XmlTag.class);
    if (tag != null && canonicalText.equals(tag.getAttributeValue(TARGET_NAMESPACE_ATTR_NAME)))
        return tag;
    final PsiFile containingFile = myElement.getContainingFile();
    if (tag != null && tag.getAttributeValue("schemaLocation", XmlUtil.XML_SCHEMA_INSTANCE_URI) == null) {
        final PsiFile file = ExternalResourceManager.getInstance().getResourceLocation(canonicalText, containingFile, tag.getAttributeValue("version"));
        if (file != null)
            return file;
    }
    if (containingFile instanceof XmlFile) {
        final XmlDocument document = ((XmlFile) containingFile).getDocument();
        assert document != null;
        final XmlTag rootTag = document.getRootTag();
        if (rootTag == null) {
            return ExternalResourceManager.getInstance().getResourceLocation(canonicalText, containingFile, null);
        }
        final XmlNSDescriptor nsDescriptor = rootTag.getNSDescriptor(canonicalText, true);
        if (nsDescriptor != null)
            return nsDescriptor.getDescriptorFile();
        final String url = ExternalResourceManager.getInstance().getResourceLocation(canonicalText, myElement.getProject());
        if (!url.equals(canonicalText)) {
            myIncorrectResourceMapped = true;
            return null;
        }
        if (tag == rootTag && (tag.getNamespace().equals(XmlUtil.XML_SCHEMA_URI) || tag.getNamespace().equals(XmlUtil.WSDL_SCHEMA_URI))) {
            for (XmlTag t : tag.getSubTags()) {
                final String name = t.getLocalName();
                if ("import".equals(name)) {
                    if (canonicalText.equals(t.getAttributeValue("namespace")))
                        return t;
                } else if (!"include".equals(name) && !"redefine".equals(name) && !"annotation".equals(name))
                    break;
            }
        }
        final PsiElement[] result = new PsiElement[1];
        processWsdlSchemas(rootTag, t -> {
            if (canonicalText.equals(t.getAttributeValue(TARGET_NAMESPACE_ATTR_NAME))) {
                result[0] = t;
                return false;
            }
            for (XmlTag anImport : t.findSubTags("import", t.getNamespace())) {
                if (canonicalText.equals(anImport.getAttributeValue("namespace"))) {
                    final XmlAttribute location = anImport.getAttribute("schemaLocation");
                    if (location != null) {
                        result[0] = FileReferenceUtil.findFile(location.getValueElement());
                    }
                }
            }
            return true;
        });
        return result[0];
    }
    return null;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

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