Collection<LookupElement> (XPathElement element) { final XPathFile xpathFile = (XPathFile)element.getContainingFile(); final ContextProvider contextProvider = ContextProvider.getContextProvider(xpathFile); final NamespaceContext nsContext = contextProvider.getNamespaceContext(); String uri; PrefixedName qn = null; if (element instanceof QNameElement) { qn = ((QNameElement)element).getQName(); if (qn != null) { QName qName = contextProvider.getQName(qn, element); if (qn.getPrefix() != null) { if (qName != null) { uri = qName.getNamespaceURI(); } else { return Collections.emptySet(); } } else { uri = null; } } else { uri = null; } } else { uri = null; } final Map<Pair<QName, Integer>, ? extends Function> functions = contextProvider.getFunctionContext().getFunctions(); final List<LookupElement> lookups = new ArrayList<>(functions.size()); for (Map.Entry<Pair<QName, Integer>, ? extends Function> entry : functions.entrySet()) { final Function functionDecl = entry.getValue(); final QName f = entry.getKey().first; final String p; if (nsContext != null) { String namespaceURI = f.getNamespaceURI(); if (uri != null && !namespaceURI.equals(uri)) { continue; } final String prefixForURI = nsContext.getPrefixForURI(namespaceURI, PsiTreeUtil.getContextOfType(element, XmlElement.class, true)); if (prefixForURI == null && namespaceURI.length() > 0) { continue; } p = qn == null || qn.getPrefix() == null ? makePrefix(prefixForURI) : ""; } else { p = ""; } lookups.add(FunctionLookup.newFunctionLookup(p + f.getLocalPart(), functionDecl)); } return lookups; }