Search in sources :

Example 1 with XPathType

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

the class XsltFunctionImpl method getFunction.

private Function getFunction() {
    final XPathType returnType = XsltCodeInsightUtil.getDeclaredType(getTag());
    final XmlTag[] params = getTag().findSubTags("param", XsltSupport.XSLT_NS);
    final Parameter[] parameters = ContainerUtil.map2Array(params, Parameter.class, PARAM_MAPPER);
    return new FunctionImpl(null, returnType != null ? returnType : XPathType.UNKNOWN, parameters) {

        @Override
        public String getName() {
            return getQName().getLocalPart();
        }
    };
}
Also used : XPathType(org.intellij.lang.xpath.psi.XPathType) FunctionImpl(org.intellij.lang.xpath.context.functions.FunctionImpl) Parameter(org.intellij.lang.xpath.context.functions.Parameter) XmlTag(com.intellij.psi.xml.XmlTag)

Example 2 with XPathType

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

the class XsltVariableImpl method getType.

@NotNull
public XPathType getType() {
    final XPathType declaredType = XsltCodeInsightUtil.getDeclaredType(getTag());
    if (declaredType != null) {
        return declaredType;
    }
    final XmlAttribute attr = getTag().getAttribute("type", XsltSupport.PLUGIN_EXTENSIONS_NS);
    if (attr != null) {
        return XPathType.fromString(attr.getValue());
    }
    final XPathExpression value = getValue();
    if (value instanceof XPathVariableReference) {
        // recursive reference <xsl:variable name="foo" select="$foo" />
        final XPathVariableReference reference = (XPathVariableReference) value;
        if (reference.resolve() == this) {
            return XPathType.UNKNOWN;
        }
    }
    return value != null ? value.getType() : XPathType.UNKNOWN;
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) XPathType(org.intellij.lang.xpath.psi.XPathType) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XPathVariableReference(org.intellij.lang.xpath.psi.XPathVariableReference) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with XPathType

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

the class XPath2ExpressionTest method doTest.

protected XPathType doTest(boolean symmetric) throws Throwable {
    myFixture.configureByFile(getTestFileName() + ".xpath2");
    final XPathExpression expression = getExpression();
    // all these cases must be green
    myFixture.checkHighlighting();
    if (symmetric && expression instanceof XPathBinaryExpression) {
        final XPathBinaryExpression expr = (XPathBinaryExpression) expression;
        if (expr.getLOperand().getType() != expr.getROperand().getType()) {
            myFixture.configureByText(XPathFileType.XPATH2, expr.getROperand().getText() + " " + expr.getOperationSign() + " " + expr.getLOperand().getText());
            assertEquals(getExpression().getType(), expression.getType());
            myFixture.checkHighlighting();
        }
    }
    final XPathType type = expression.getType();
    if (type instanceof XPath2SequenceType) {
        return ((XPath2SequenceType) type).getType();
    }
    return type;
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) XPathType(org.intellij.lang.xpath.psi.XPathType) XPathBinaryExpression(org.intellij.lang.xpath.psi.XPathBinaryExpression) XPath2SequenceType(org.intellij.lang.xpath.psi.XPath2SequenceType)

Example 4 with XPathType

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

the class FunctionDeclarationParsing method parseFuntionDeclaration.

public static Pair<String, ? extends Function> parseFuntionDeclaration(String decl) {
    final Lexer lexer = new FilterLexer(XPathLexer.create(true), new FilterLexer.SetFilter(TokenSet.create(XPathTokenTypes.WHITESPACE)));
    lexer.start(decl);
    String prefix = "";
    if (lexer.getTokenType() == XPathTokenTypes.EXT_PREFIX) {
        prefix = lexer.getTokenText();
        lexer.advance();
        match(lexer, XPathTokenTypes.COL);
    }
    final String name = match(lexer, XPathTokenTypes.FUNCTION_NAME);
    match(lexer, XPathTokenTypes.LPAREN);
    final List<Parameter> parameters = new ArrayList<>();
    while (lexer.getTokenType() != XPathTokenTypes.RPAREN) {
        if (lexer.getTokenType() == XPathTokenTypes.DOTDOT) {
            lexer.advance();
            match(lexer, XPathTokenTypes.DOT);
            parameters.add(new Parameter(XPathType.ANY, Parameter.Kind.VARARG));
        } else {
            match(lexer, XPathTokenTypes.DOLLAR);
            match(lexer, XPathTokenTypes.VARIABLE_NAME);
            match(lexer, XPath2TokenTypes.AS);
            final String type = parseType(lexer);
            final XPath2SequenceType.Cardinality indicator = parseCardinality(lexer);
            parameters.add(new Parameter(mapType(type, indicator), Parameter.Kind.REQUIRED));
        }
        if (lexer.getTokenType() == XPathTokenTypes.COMMA) {
            lexer.advance();
        }
    }
    lexer.advance();
    match(lexer, XPath2TokenTypes.AS);
    final String ret = parseType(lexer);
    final XPath2SequenceType.Cardinality indicator = parseCardinality(lexer);
    final XPathType returnType = mapType(ret, indicator);
    return Pair.create(prefix, new FunctionImpl(name, returnType, parameters.toArray(new Parameter[parameters.size()])));
}
Also used : Lexer(com.intellij.lexer.Lexer) XPathLexer(org.intellij.lang.xpath.XPathLexer) FilterLexer(com.intellij.lexer.FilterLexer) XPathType(org.intellij.lang.xpath.psi.XPathType) ArrayList(java.util.ArrayList) XPath2SequenceType(org.intellij.lang.xpath.psi.XPath2SequenceType) FilterLexer(com.intellij.lexer.FilterLexer)

Aggregations

XPathType (org.intellij.lang.xpath.psi.XPathType)4 XPath2SequenceType (org.intellij.lang.xpath.psi.XPath2SequenceType)2 XPathExpression (org.intellij.lang.xpath.psi.XPathExpression)2 FilterLexer (com.intellij.lexer.FilterLexer)1 Lexer (com.intellij.lexer.Lexer)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 ArrayList (java.util.ArrayList)1 XPathLexer (org.intellij.lang.xpath.XPathLexer)1 FunctionImpl (org.intellij.lang.xpath.context.functions.FunctionImpl)1 Parameter (org.intellij.lang.xpath.context.functions.Parameter)1 XPathBinaryExpression (org.intellij.lang.xpath.psi.XPathBinaryExpression)1 XPathVariableReference (org.intellij.lang.xpath.psi.XPathVariableReference)1 NotNull (org.jetbrains.annotations.NotNull)1