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