use of org.intellij.lang.xpath.context.NamespaceContext in project intellij-community by JetBrains.
the class XPathAnnotator method checkPrefixReferences.
private static void checkPrefixReferences(AnnotationHolder holder, QNameElement element, ContextProvider myProvider) {
final PsiReference[] references = element.getReferences();
for (PsiReference reference : references) {
if (reference instanceof PrefixReference) {
final PrefixReference pr = ((PrefixReference) reference);
if (!pr.isSoft() && pr.isUnresolved()) {
final TextRange range = pr.getRangeInElement().shiftRight(pr.getElement().getTextRange().getStartOffset());
final Annotation a = holder.createErrorAnnotation(range, "Unresolved namespace prefix '" + pr.getCanonicalText() + "'");
a.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
final NamespaceContext namespaceContext = myProvider.getNamespaceContext();
final PrefixedName qName = element.getQName();
if (namespaceContext != null && qName != null) {
final IntentionAction[] fixes = namespaceContext.getUnresolvedNamespaceFixes(reference, qName.getLocalName());
for (IntentionAction fix : fixes) {
a.registerFix(fix);
}
}
}
}
}
}
use of org.intellij.lang.xpath.context.NamespaceContext in project intellij-community by JetBrains.
the class CompletionLists method getFunctionCompletions.
public static Collection<Lookup> getFunctionCompletions(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<Lookup> 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;
}
Aggregations