use of com.intellij.xml.XmlSchemaProvider in project intellij-community by JetBrains.
the class XmlLocationCompletionContributor method completeNamespace.
private static Object[] completeNamespace(PsiElement myElement) {
final XmlFile file = (XmlFile) myElement.getContainingFile();
PsiElement parent = myElement.getParent();
final Set<Object> preferred = new HashSet<>();
if (parent instanceof XmlAttribute && "xmlns".equals(((XmlAttribute) parent).getName())) {
XmlNamespaceHelper helper = XmlNamespaceHelper.getHelper(file);
preferred.addAll(helper.guessUnboundNamespaces(parent.getParent(), file));
}
Set<String> list = new HashSet<>();
for (XmlSchemaProvider provider : Extensions.getExtensions(XmlSchemaProvider.EP_NAME)) {
if (provider.isAvailable(file)) {
list.addAll(provider.getAvailableNamespaces(file, null));
}
}
if (!list.isEmpty()) {
return ArrayUtil.toObjectArray(list);
}
Object[] resourceUrls = ExternalResourceManagerEx.getInstanceEx().getUrlsByNamespace(myElement.getProject()).keySet().toArray();
final XmlDocument document = file.getDocument();
assert document != null;
XmlTag rootTag = document.getRootTag();
final ArrayList<String> additionalNs = new ArrayList<>();
if (rootTag != null)
URLReference.processWsdlSchemas(rootTag, xmlTag -> {
final String s = xmlTag.getAttributeValue(URLReference.TARGET_NAMESPACE_ATTR_NAME);
if (s != null) {
additionalNs.add(s);
}
return true;
});
resourceUrls = ArrayUtil.mergeArrays(resourceUrls, ArrayUtil.toStringArray(additionalNs));
return ContainerUtil.map2Array(resourceUrls, o -> {
LookupElementBuilder builder = LookupElementBuilder.create(o);
return preferred.contains(o) ? PrioritizedLookupElement.withPriority(builder, 100) : builder;
});
}
Aggregations