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