Search in sources :

Example 1 with RelaxedHtmlFromSchemaElementDescriptor

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;
    });
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlExtension(com.intellij.xml.XmlExtension) RelaxedHtmlFromSchemaElementDescriptor(com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptorImpl(com.intellij.xml.impl.schema.XmlElementDescriptorImpl) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

RelaxedHtmlFromSchemaElementDescriptor (com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor)1 PsiElement (com.intellij.psi.PsiElement)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 XmlExtension (com.intellij.xml.XmlExtension)1 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)1 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)1 XmlElementDescriptorImpl (com.intellij.xml.impl.schema.XmlElementDescriptorImpl)1