Search in sources :

Example 1 with XmlNSDescriptor

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

the class HtmlUtil method tagHasHtml5Schema.

public static boolean tagHasHtml5Schema(@NotNull XmlTag context) {
    XmlElementDescriptor descriptor = context.getDescriptor();
    if (descriptor != null) {
        XmlNSDescriptor nsDescriptor = descriptor.getNSDescriptor();
        XmlFile descriptorFile = nsDescriptor != null ? nsDescriptor.getDescriptorFile() : null;
        String descriptorPath = descriptorFile != null ? descriptorFile.getVirtualFile().getPath() : null;
        return Comparing.equal(Html5SchemaProvider.getHtml5SchemaLocation(), descriptorPath) || Comparing.equal(Html5SchemaProvider.getXhtml5SchemaLocation(), descriptorPath);
    }
    return false;
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 2 with XmlNSDescriptor

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

Example 3 with XmlNSDescriptor

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

the class XmlTagImpl method getImplicitNamespaceDescriptor.

@Nullable
private XmlNSDescriptor getImplicitNamespaceDescriptor(String ns) {
    PsiFile file = getContainingFile();
    if (file == null)
        return null;
    Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module != null) {
        for (ImplicitNamespaceDescriptorProvider provider : Extensions.getExtensions(ImplicitNamespaceDescriptorProvider.EP_NAME)) {
            XmlNSDescriptor nsDescriptor = provider.getNamespaceDescriptor(module, ns, file);
            if (nsDescriptor != null)
                return nsDescriptor;
        }
    }
    return null;
}
Also used : ImplicitNamespaceDescriptorProvider(com.intellij.javaee.ImplicitNamespaceDescriptorProvider) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with XmlNSDescriptor

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

the class XmlNSDescriptorImpl method findTypeDescriptorImpl.

@Nullable
private TypeDescriptor findTypeDescriptorImpl(XmlTag rootTag, final String name, String namespace) {
    return RecursionManager.createGuard("findDescriptor").doPreventingRecursion(rootTag, true, () -> {
        XmlNSDescriptorImpl responsibleDescriptor = this;
        if (namespace != null && namespace.length() != 0 && !namespace.equals(getDefaultNamespace())) {
            final XmlNSDescriptor nsDescriptor = rootTag.getNSDescriptor(namespace, true);
            if (nsDescriptor instanceof XmlNSDescriptorImpl) {
                responsibleDescriptor = (XmlNSDescriptorImpl) nsDescriptor;
            }
        }
        if (responsibleDescriptor != this) {
            return responsibleDescriptor.findTypeDescriptor(name, namespace);
        }
        if (rootTag == null)
            return null;
        final Pair<QNameKey, XmlTag> pair = Pair.create(new QNameKey(name, namespace), rootTag);
        final CachedValue<TypeDescriptor> descriptor = myTypesMap.get(pair);
        if (descriptor != null) {
            TypeDescriptor value = descriptor.getValue();
            if (value == null || (value instanceof ComplexTypeDescriptor && ((ComplexTypeDescriptor) value).getDeclaration().isValid())) {
                return value;
            }
        }
        XmlTag[] tags = rootTag.getSubTags();
        return doFindIn(tags, name, namespace, pair, rootTag);
    });
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with XmlNSDescriptor

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

the class XmlNSDescriptorImpl method getAttributeImpl.

@Nullable
private XmlAttributeDescriptor getAttributeImpl(String localName, String namespace, @Nullable Set<XmlTag> visited) {
    if (myTag == null)
        return null;
    XmlNSDescriptor nsDescriptor = myTag.getNSDescriptor(namespace, true);
    if (nsDescriptor != this && nsDescriptor instanceof XmlNSDescriptorImpl) {
        return ((XmlNSDescriptorImpl) nsDescriptor).getAttributeImpl(localName, namespace, visited);
    }
    if (visited == null)
        visited = new HashSet<>(1);
    else if (visited.contains(myTag))
        return null;
    visited.add(myTag);
    XmlTag[] tags = myTag.getSubTags();
    for (XmlTag tag : tags) {
        if (equalsToSchemaName(tag, ATTRIBUTE_TAG_NAME)) {
            String name = tag.getAttributeValue("name");
            if (name != null) {
                if (checkElementNameEquivalence(localName, namespace, name, tag)) {
                    return createAttributeDescriptor(tag);
                }
            }
        } else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (equalsToSchemaName(tag, IMPORT_TAG_NAME) && namespace.equals(tag.getAttributeValue("namespace")))) {
            final String schemaLocation = tag.getAttributeValue("schemaLocation");
            if (schemaLocation != null) {
                final XmlFile xmlFile = XmlUtil.findNamespace(myTag.getContainingFile(), schemaLocation);
                if (xmlFile != null) {
                    final XmlDocument includedDocument = xmlFile.getDocument();
                    if (includedDocument != null) {
                        final PsiMetaData data = includedDocument.getMetaData();
                        if (data instanceof XmlNSDescriptorImpl) {
                            final XmlAttributeDescriptor attributeDescriptor = ((XmlNSDescriptorImpl) data).getAttributeImpl(localName, namespace, visited);
                            if (attributeDescriptor != null) {
                                final CachedValue<XmlAttributeDescriptor> value = CachedValuesManager.getManager(includedDocument.getProject()).createCachedValue(() -> {
                                    Object[] deps = attributeDescriptor.getDependences();
                                    if (deps.length == 0) {
                                        LOG.error(attributeDescriptor + " (" + attributeDescriptor.getClass() + ") returned no dependencies");
                                    }
                                    return new CachedValueProvider.Result<>(attributeDescriptor, deps);
                                }, false);
                                return value.getValue();
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : CachedValueProvider(com.intellij.psi.util.CachedValueProvider) XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) CachedValue(com.intellij.psi.util.CachedValue) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) THashSet(gnu.trove.THashSet) 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