Search in sources :

Example 1 with XmlNSDescriptorSequence

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

the class XmlDocumentImpl method getNsDescriptorFormDocType.

@Nullable
private XmlNSDescriptor getNsDescriptorFormDocType(final XmlDoctype doctype, final XmlFile containingFile, final boolean forHtml) {
    XmlNSDescriptor descriptor = getNSDescriptorFromMetaData(doctype.getMarkupDecl(), true);
    final String filePath = getFilePathForLogging(containingFile);
    final String dtdUri = XmlUtil.getDtdUri(doctype);
    LOG.debug("DTD url for doctype " + doctype.getText() + " in file " + filePath + " is " + dtdUri);
    if (dtdUri != null && !dtdUri.isEmpty()) {
        XmlFile xmlFile = XmlUtil.findNamespace(containingFile, dtdUri);
        if (xmlFile == null) {
            // try to auto-detect it
            xmlFile = XmlNamespaceIndex.guessDtd(dtdUri, containingFile);
        }
        final String schemaFilePath = getFilePathForLogging(xmlFile);
        LOG.debug("Schema file for " + filePath + " is " + schemaFilePath);
        XmlNSDescriptor descriptorFromDtd = getNSDescriptorFromMetaData(xmlFile == null ? null : xmlFile.getDocument(), forHtml);
        LOG.debug("Descriptor from meta data for schema file " + schemaFilePath + " is " + (descriptorFromDtd != null ? descriptorFromDtd.getClass().getCanonicalName() : "NULL"));
        if (descriptor != null && descriptorFromDtd != null) {
            descriptor = new XmlNSDescriptorSequence(new XmlNSDescriptor[] { descriptor, descriptorFromDtd });
        } else if (descriptorFromDtd != null) {
            descriptor = descriptorFromDtd;
        }
    }
    return descriptor;
}
Also used : XmlNSDescriptorSequence(com.intellij.xml.util.XmlNSDescriptorSequence) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with XmlNSDescriptorSequence

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

the class XmlElementDescriptorImpl method doCollectXmlDescriptors.

// Read-only action
@Override
protected final XmlElementDescriptor[] doCollectXmlDescriptors(final XmlTag context) {
    final LinkedHashSet<XmlElementDescriptor> result = new LinkedHashSet<>();
    final XmlElementContentSpec contentSpecElement = myElementDecl.getContentSpecElement();
    final XmlNSDescriptor nsDescriptor = getNSDescriptor();
    final XmlNSDescriptor NSDescriptor = nsDescriptor != null ? nsDescriptor : getNsDescriptorFrom(context);
    XmlUtil.processXmlElements(contentSpecElement, new PsiElementProcessor() {

        @Override
        public boolean execute(@NotNull PsiElement child) {
            if (child instanceof XmlToken) {
                final XmlToken token = (XmlToken) child;
                if (token.getTokenType() == XmlTokenType.XML_NAME) {
                    final String text = child.getText();
                    XmlElementDescriptor element = getElementDescriptor(text, NSDescriptor);
                    if (element != null) {
                        result.add(element);
                    }
                } else if (token.getTokenType() == XmlTokenType.XML_CONTENT_ANY) {
                    if (NSDescriptor instanceof XmlNSDescriptorImpl) {
                        ContainerUtil.addAll(result, ((XmlNSDescriptorImpl) NSDescriptor).getElements());
                    } else if (NSDescriptor instanceof XmlNSDescriptorSequence) {
                        for (XmlNSDescriptor xmlNSDescriptor : ((XmlNSDescriptorSequence) NSDescriptor).getSequence()) {
                            if (xmlNSDescriptor instanceof XmlNSDescriptorImpl) {
                                ContainerUtil.addAll(result, ((XmlNSDescriptorImpl) xmlNSDescriptor).getElements());
                            }
                        }
                    }
                }
            }
            return true;
        }
    }, true, false, XmlUtil.getContainingFile(getDeclaration()));
    return result.toArray(new XmlElementDescriptor[result.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XmlNSDescriptorSequence(com.intellij.xml.util.XmlNSDescriptorSequence) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)2 XmlNSDescriptorSequence (com.intellij.xml.util.XmlNSDescriptorSequence)2 PsiElement (com.intellij.psi.PsiElement)1 PsiElementProcessor (com.intellij.psi.search.PsiElementProcessor)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 LinkedHashSet (java.util.LinkedHashSet)1 Nullable (org.jetbrains.annotations.Nullable)1