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