Search in sources :

Example 71 with XmlNSDescriptor

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

the class TagNameVariantCollector method processVariantsInNamespace.

private static void processVariantsInNamespace(final String namespace, final XmlTag element, final List<XmlElementDescriptor> variants, final XmlElementDescriptor elementDescriptor, final String elementNamespace, final Map<String, XmlElementDescriptor> descriptorsMap, final Set<XmlNSDescriptor> visited, XmlTag parent, final XmlExtension extension) {
    if (descriptorsMap.containsKey(namespace)) {
        final XmlElementDescriptor descriptor = descriptorsMap.get(namespace);
        if (isAcceptableNs(element, elementDescriptor, elementNamespace, namespace)) {
            for (XmlElementDescriptor containedDescriptor : descriptor.getElementsDescriptors(parent)) {
                if (containedDescriptor != null)
                    variants.add(containedDescriptor);
            }
        }
        if (element instanceof HtmlTag) {
            HtmlUtil.addHtmlSpecificCompletions(descriptor, element, variants);
        }
        visited.add(descriptor.getNSDescriptor());
    } else {
        // their element descriptors (prev if section)
        if (namespace == null)
            return;
        if (namespace.isEmpty() && !visited.isEmpty())
            return;
        XmlNSDescriptor nsDescriptor = getDescriptor(element, namespace, true, extension);
        if (nsDescriptor == null) {
            if (!descriptorsMap.isEmpty())
                return;
            nsDescriptor = getDescriptor(element, namespace, false, extension);
        }
        if (nsDescriptor != null && !visited.contains(nsDescriptor) && isAcceptableNs(element, elementDescriptor, elementNamespace, namespace)) {
            visited.add(nsDescriptor);
            final XmlElementDescriptor[] rootElementsDescriptors = nsDescriptor.getRootElementsDescriptors(PsiTreeUtil.getParentOfType(element, XmlDocument.class));
            final XmlTag parentTag = extension.getParentTagForNamespace(element, nsDescriptor);
            final XmlElementDescriptor parentDescriptor;
            if (parentTag == element.getParentTag()) {
                parentDescriptor = elementDescriptor;
            } else {
                assert parentTag != null;
                parentDescriptor = parentTag.getDescriptor();
            }
            for (XmlElementDescriptor candidateDescriptor : rootElementsDescriptors) {
                if (candidateDescriptor != null && couldContainDescriptor(parentTag, parentDescriptor, candidateDescriptor, namespace, false)) {
                    variants.add(candidateDescriptor);
                }
            }
        }
    }
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) HtmlTag(com.intellij.psi.html.HtmlTag) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 72 with XmlNSDescriptor

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

the class XmlTagImpl method getNamespaceByPrefix.

@Override
@NotNull
public String getNamespaceByPrefix(String prefix) {
    BidirectionalMap<String, String> map = getNamespaceMap();
    if (map != null) {
        final String ns = map.get(prefix);
        if (ns != null)
            return ns;
    }
    XmlTag parentTag = getParentTag();
    if (parentTag != null)
        return parentTag.getNamespaceByPrefix(prefix);
    //The prefix 'xml' is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared
    if (XML_NS_PREFIX.equals(prefix))
        return XmlUtil.XML_NAMESPACE_URI;
    if (!prefix.isEmpty() && !hasNamespaceDeclarations() && getNamespacePrefix().equals(prefix)) {
        // When there is no namespace declarations then qualified names should be just used in dtds
        // this implies that we may have "" namespace prefix ! (see last paragraph in Namespaces in Xml, Section 5)
        String result = ourGuard.doPreventingRecursion("getNsByPrefix", true, () -> {
            final String nsFromEmptyPrefix = getNamespaceByPrefix("");
            final XmlNSDescriptor nsDescriptor = getNSDescriptor(nsFromEmptyPrefix, false);
            final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(this) : null;
            final String nameFromRealDescriptor = descriptor != null && descriptor.getDeclaration() != null && descriptor.getDeclaration().isPhysical() ? descriptor.getName() : "";
            if (nameFromRealDescriptor.equals(getName()))
                return nsFromEmptyPrefix;
            return XmlUtil.EMPTY_URI;
        });
        if (result != null) {
            return result;
        }
    }
    return XmlUtil.EMPTY_URI;
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 73 with XmlNSDescriptor

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

the class XmlTagImpl method getNSDescriptor.

@Override
public XmlNSDescriptor getNSDescriptor(final String namespace, boolean strict) {
    final XmlTag parentTag = getParentTag();
    if (parentTag == null && namespace.equals(XmlUtil.XHTML_URI)) {
        final XmlNSDescriptor descriptor = getDtdDescriptor(XmlUtil.getContainingFile(this));
        if (descriptor != null) {
            return descriptor;
        }
    }
    Map<String, CachedValue<XmlNSDescriptor>> map = getNSDescriptorsMap();
    final CachedValue<XmlNSDescriptor> descriptor = map.get(namespace);
    if (descriptor != null) {
        final XmlNSDescriptor value = descriptor.getValue();
        if (value != null) {
            return value;
        }
    }
    if (parentTag == null) {
        final XmlDocument parentOfType = PsiTreeUtil.getParentOfType(this, XmlDocument.class);
        if (parentOfType == null) {
            return null;
        }
        return parentOfType.getDefaultNSDescriptor(namespace, strict);
    }
    return parentTag.getNSDescriptor(namespace, strict);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor)

Example 74 with XmlNSDescriptor

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

the class XmlTagImpl method computeElementDescriptor.

@Nullable
protected XmlElementDescriptor computeElementDescriptor() {
    for (XmlElementDescriptorProvider provider : Extensions.getExtensions(XmlElementDescriptorProvider.EP_NAME)) {
        XmlElementDescriptor elementDescriptor = provider.getDescriptor(this);
        if (elementDescriptor != null) {
            return elementDescriptor;
        }
    }
    final String namespace = getNamespace();
    if (XmlUtil.EMPTY_URI.equals(namespace)) {
        //nonqualified items
        final XmlTag parent = getParentTag();
        if (parent != null) {
            final XmlElementDescriptor descriptor = parent.getDescriptor();
            if (descriptor != null) {
                XmlElementDescriptor fromParent = descriptor.getElementDescriptor(this, parent);
                if (fromParent != null && !(fromParent instanceof AnyXmlElementDescriptor)) {
                    return fromParent;
                }
            }
        }
    }
    XmlElementDescriptor elementDescriptor = null;
    final XmlNSDescriptor nsDescriptor = getNSDescriptor(namespace, false);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Descriptor for namespace " + namespace + " is " + (nsDescriptor != null ? nsDescriptor.getClass().getCanonicalName() : "NULL"));
    }
    if (nsDescriptor != null) {
        if (!DumbService.getInstance(getProject()).isDumb() || DumbService.isDumbAware(nsDescriptor)) {
            elementDescriptor = nsDescriptor.getElementDescriptor(this);
        }
    }
    if (elementDescriptor == null) {
        return XmlUtil.findXmlDescriptorByType(this);
    }
    return elementDescriptor;
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 75 with XmlNSDescriptor

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

the class XmlDocumentImpl method updateSelfDependentDtdDescriptors.

private void updateSelfDependentDtdDescriptors(XmlDocumentImpl copy, HashMap<String, CachedValue<XmlNSDescriptor>> cacheStrict, HashMap<String, CachedValue<XmlNSDescriptor>> cacheNotStrict) {
    copy.myDefaultDescriptorsCacheNotStrict = ContainerUtil.newConcurrentMap();
    copy.myDefaultDescriptorsCacheStrict = ContainerUtil.newConcurrentMap();
    for (Map.Entry<String, CachedValue<XmlNSDescriptor>> e : cacheStrict.entrySet()) {
        if (e.getValue().hasUpToDateValue()) {
            final XmlNSDescriptor nsDescriptor = e.getValue().getValue();
            if (!isGeneratedFromDtd(nsDescriptor))
                copy.myDefaultDescriptorsCacheStrict.put(e.getKey(), e.getValue());
        }
    }
    for (Map.Entry<String, CachedValue<XmlNSDescriptor>> e : cacheNotStrict.entrySet()) {
        if (e.getValue().hasUpToDateValue()) {
            final XmlNSDescriptor nsDescriptor = e.getValue().getValue();
            if (!isGeneratedFromDtd(nsDescriptor))
                copy.myDefaultDescriptorsCacheNotStrict.put(e.getKey(), e.getValue());
        }
    }
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) CachedValue(com.intellij.psi.util.CachedValue) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

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