Search in sources :

Example 1 with XPathFunction

use of org.intellij.lang.xpath.psi.XPathFunction in project intellij-community by JetBrains.

the class XsltDocumentationProvider method getUrlFor.

@Nullable
public List<String> getUrlFor(PsiElement psiElement, PsiElement psiElement1) {
    if (psiElement instanceof XsltElement)
        return null;
    final String category;
    final String name;
    final String tagName = getTagName(psiElement);
    if (tagName != null) {
        name = tagName;
        category = "element";
    } else if (psiElement instanceof XPathFunction) {
        name = ((XPathFunction) psiElement).getName();
        category = "function";
    } else if (psiElement instanceof DocElement) {
        name = ((DocElement) psiElement).getName();
        category = ((DocElement) psiElement).getCategory();
    } else {
        return null;
    }
    try {
        final Document document = getDocumentationDocument();
        final XPath xPath = XPath.newInstance("//x:" + category + "[@name = '" + name + "']");
        xPath.addNamespace("x", document.getRootElement().getNamespaceURI());
        final Element e = (Element) xPath.selectSingleNode(document);
        if (e != null) {
            return Collections.singletonList(e.getParentElement().getAttributeValue("base") + e.getAttributeValue("href"));
        }
    } catch (Exception e) {
        Logger.getInstance(getClass().getName()).error(e);
    }
    return null;
}
Also used : XPath(org.jdom.xpath.XPath) XPathFunction(org.intellij.lang.xpath.psi.XPathFunction) XsltElement(org.intellij.lang.xpath.xslt.psi.XsltElement) XsltElement(org.intellij.lang.xpath.xslt.psi.XsltElement) LightElement(com.intellij.psi.impl.light.LightElement) Element(org.jdom.Element) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with XPathFunction

use of org.intellij.lang.xpath.psi.XPathFunction in project intellij-community by JetBrains.

the class XPathParameterInfoHandler method updateUI.

public void updateUI(XPathFunction function, @NotNull ParameterInfoUIContext context) {
    final Function declaration = function.getDeclaration();
    if (declaration != null) {
        if (declaration.getParameters().length > 0) {
            final String signature = declaration.buildSignature();
            final int length = declaration.getName().length();
            final String hint = signature.substring(length + 1, signature.length() - 1);
            final int currentParameterIndex = context.getCurrentParameterIndex();
            if (currentParameterIndex < 0 || currentParameterIndex >= declaration.getParameters().length) {
                context.setupUIComponentPresentation(hint, -1, -1, false, false, false, context.getDefaultParameterColor());
            } else {
                final String[] ps = hint.split(",");
                final TextRange[] ts = new TextRange[ps.length];
                int start = 0;
                for (int i = 0; i < ps.length; i++) {
                    String p = ps[i];
                    ts[i] = TextRange.from(start, p.length());
                    start += p.length() + 1;
                }
                final TextRange range = ts[currentParameterIndex];
                context.setupUIComponentPresentation(hint, range.getStartOffset(), range.getEndOffset(), false, false, false, context.getDefaultParameterColor());
            }
        } else {
            context.setupUIComponentPresentation(noParamsMessage(), -1, -1, false, false, false, context.getDefaultParameterColor());
        }
    }
}
Also used : Function(org.intellij.lang.xpath.context.functions.Function) XPathFunction(org.intellij.lang.xpath.psi.XPathFunction) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

XPathFunction (org.intellij.lang.xpath.psi.XPathFunction)2 TextRange (com.intellij.openapi.util.TextRange)1 LightElement (com.intellij.psi.impl.light.LightElement)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 IOException (java.io.IOException)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 Function (org.intellij.lang.xpath.context.functions.Function)1 XsltElement (org.intellij.lang.xpath.xslt.psi.XsltElement)1 Document (org.jdom.Document)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1 XPath (org.jdom.xpath.XPath)1 Nullable (org.jetbrains.annotations.Nullable)1