Search in sources :

Example 6 with ContextProvider

use of org.intellij.lang.xpath.context.ContextProvider in project intellij-community by JetBrains.

the class XPathAnnotator method visitXPath2TypeElement.

@Override
public void visitXPath2TypeElement(XPath2TypeElement o) {
    final ContextProvider contextProvider = o.getXPathContext();
    checkPrefixReferences(myHolder, o, contextProvider);
    if (o.getDeclaredType() == XPathType.UNKNOWN) {
        final PsiReference[] references = o.getReferences();
        for (PsiReference reference : references) {
            if (reference instanceof XsltReferenceContributor.SchemaTypeReference) {
                if (!reference.isSoft() && reference.resolve() == null) {
                    final String message = ((EmptyResolveMessageProvider) reference).getUnresolvedMessagePattern();
                    final Annotation annotation = myHolder.createErrorAnnotation(reference.getRangeInElement().shiftRight(o.getTextOffset()), message);
                    annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
                }
            }
        }
    }
    super.visitXPath2TypeElement(o);
}
Also used : EmptyResolveMessageProvider(com.intellij.codeInsight.daemon.EmptyResolveMessageProvider) PsiReference(com.intellij.psi.PsiReference) ContextProvider(org.intellij.lang.xpath.context.ContextProvider) Annotation(com.intellij.lang.annotation.Annotation)

Example 7 with ContextProvider

use of org.intellij.lang.xpath.context.ContextProvider in project intellij-community by JetBrains.

the class XPathAnnotator method visitXPathNodeTest.

@Override
public void visitXPathNodeTest(XPathNodeTest o) {
    final ContextProvider contextProvider = o.getXPathContext();
    checkNodeTest(contextProvider, myHolder, o);
}
Also used : ContextProvider(org.intellij.lang.xpath.context.ContextProvider)

Example 8 with ContextProvider

use of org.intellij.lang.xpath.context.ContextProvider in project intellij-community by JetBrains.

the class XPathAnnotator method visitXPathFunctionCall.

@Override
public void visitXPathFunctionCall(XPathFunctionCall o) {
    final ContextProvider contextProvider = o.getXPathContext();
    checkFunctionCall(myHolder, o, contextProvider);
    super.visitXPathFunctionCall(o);
}
Also used : ContextProvider(org.intellij.lang.xpath.context.ContextProvider)

Example 9 with ContextProvider

use of org.intellij.lang.xpath.context.ContextProvider 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;
}
Also used : QName(javax.xml.namespace.QName) ContextProvider(org.intellij.lang.xpath.context.ContextProvider) Function(org.intellij.lang.xpath.context.functions.Function) XPathFile(org.intellij.lang.xpath.XPathFile) NamespaceContext(org.intellij.lang.xpath.context.NamespaceContext) XmlElement(com.intellij.psi.xml.XmlElement) Pair(com.intellij.openapi.util.Pair)

Aggregations

ContextProvider (org.intellij.lang.xpath.context.ContextProvider)9 NamespaceContext (org.intellij.lang.xpath.context.NamespaceContext)3 XmlElement (com.intellij.psi.xml.XmlElement)2 EmptyResolveMessageProvider (com.intellij.codeInsight.daemon.EmptyResolveMessageProvider)1 Annotation (com.intellij.lang.annotation.Annotation)1 Pair (com.intellij.openapi.util.Pair)1 PsiReference (com.intellij.psi.PsiReference)1 QName (javax.xml.namespace.QName)1 XPathFile (org.intellij.lang.xpath.XPathFile)1 VariableContext (org.intellij.lang.xpath.context.VariableContext)1 Function (org.intellij.lang.xpath.context.functions.Function)1 Nullable (org.jetbrains.annotations.Nullable)1