use of com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor in project intellij-community by JetBrains.
the class TagNameVariantCollector method getTagDescriptors.
public static List<XmlElementDescriptor> getTagDescriptors(final XmlTag element, final Collection<String> namespaces, @Nullable List<String> nsInfo) {
XmlElementDescriptor elementDescriptor = null;
String elementNamespace = element.getNamespacePrefix().isEmpty() ? null : element.getNamespace();
final Map<String, XmlElementDescriptor> descriptorsMap = new HashMap<>();
PsiElement context = element.getParent();
PsiElement curElement = element.getParent();
while (curElement instanceof XmlTag) {
final XmlTag declarationTag = (XmlTag) curElement;
final String namespace = declarationTag.getNamespace();
if (!descriptorsMap.containsKey(namespace)) {
final XmlElementDescriptor descriptor = declarationTag.getDescriptor();
if (descriptor != null) {
descriptorsMap.put(namespace, descriptor);
if (elementDescriptor == null) {
elementDescriptor = descriptor;
if (elementNamespace == null) {
elementNamespace = namespace;
}
}
}
}
curElement = curElement.getContext();
}
final Set<XmlNSDescriptor> visited = new HashSet<>();
final XmlExtension extension = XmlExtension.getExtension(element.getContainingFile());
final ArrayList<XmlElementDescriptor> variants = new ArrayList<>();
for (final String namespace : namespaces) {
final int initialSize = variants.size();
processVariantsInNamespace(namespace, element, variants, elementDescriptor, elementNamespace, descriptorsMap, visited, context instanceof XmlTag ? (XmlTag) context : element, extension);
if (nsInfo != null) {
for (int i = initialSize; i < variants.size(); i++) {
XmlElementDescriptor descriptor = variants.get(i);
nsInfo.add(descriptor instanceof XmlElementDescriptorImpl && !(descriptor instanceof RelaxedHtmlFromSchemaElementDescriptor) ? ((XmlElementDescriptorImpl) descriptor).getNamespaceByContext(element) : namespace);
}
}
}
final boolean hasPrefix = StringUtil.isNotEmpty(element.getNamespacePrefix());
return ContainerUtil.filter(variants, descriptor -> {
if (descriptor instanceof AnyXmlElementDescriptor) {
return false;
} else if (hasPrefix && descriptor instanceof XmlElementDescriptorImpl && !namespaces.contains(((XmlElementDescriptorImpl) descriptor).getNamespace())) {
return false;
}
return true;
});
}
Aggregations