Search in sources :

Example 11 with SpelNodeImpl

use of cn.taketoday.expression.spel.ast.SpelNodeImpl in project today-infrastructure by TAKETODAY.

the class InternalSpelExpressionParser method maybeEatTypeReference.

private boolean maybeEatTypeReference() {
    if (peekToken(TokenKind.IDENTIFIER)) {
        Token typeName = peekToken();
        Assert.state(typeName != null, "Expected token");
        if (!"T".equals(typeName.stringValue())) {
            return false;
        }
        // It looks like a type reference but is T being used as a map key?
        Token t = takeToken();
        if (peekToken(TokenKind.RSQUARE)) {
            // looks like 'T]' (T is map key)
            push(new PropertyOrFieldReference(false, t.stringValue(), t.startPos, t.endPos));
            return true;
        }
        eatToken(TokenKind.LPAREN);
        SpelNodeImpl node = eatPossiblyQualifiedId();
        // dotted qualified id
        // Are there array dimensions?
        int dims = 0;
        while (peekToken(TokenKind.LSQUARE, true)) {
            eatToken(TokenKind.RSQUARE);
            dims++;
        }
        eatToken(TokenKind.RPAREN);
        this.constructedNodes.push(new TypeReference(typeName.startPos, typeName.endPos, node, dims));
        return true;
    }
    return false;
}
Also used : SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) PropertyOrFieldReference(cn.taketoday.expression.spel.ast.PropertyOrFieldReference) TypeReference(cn.taketoday.expression.spel.ast.TypeReference)

Example 12 with SpelNodeImpl

use of cn.taketoday.expression.spel.ast.SpelNodeImpl in project today-infrastructure by TAKETODAY.

the class InternalSpelExpressionParser method maybeEatMethodOrProperty.

// This is complicated due to the support for dollars in identifiers.
// Dollars are normally separate tokens but there we want to combine
// a series of identifiers and dollars into a single identifier.
private boolean maybeEatMethodOrProperty(boolean nullSafeNavigation) {
    if (peekToken(TokenKind.IDENTIFIER)) {
        Token methodOrPropertyName = takeToken();
        SpelNodeImpl[] args = maybeEatMethodArgs();
        if (args == null) {
            // property
            push(new PropertyOrFieldReference(nullSafeNavigation, methodOrPropertyName.stringValue(), methodOrPropertyName.startPos, methodOrPropertyName.endPos));
            return true;
        }
        // method reference
        push(new MethodReference(nullSafeNavigation, methodOrPropertyName.stringValue(), methodOrPropertyName.startPos, methodOrPropertyName.endPos, args));
        // TODO what is the end position for a method reference? the name or the last arg?
        return true;
    }
    return false;
}
Also used : SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) MethodReference(cn.taketoday.expression.spel.ast.MethodReference) PropertyOrFieldReference(cn.taketoday.expression.spel.ast.PropertyOrFieldReference)

Example 13 with SpelNodeImpl

use of cn.taketoday.expression.spel.ast.SpelNodeImpl in project today-framework by TAKETODAY.

the class SpelCompilationCoverageTests method getAst.

// Helper methods
private SpelNodeImpl getAst() {
    SpelExpression spelExpression = (SpelExpression) expression;
    SpelNode ast = spelExpression.getAST();
    return (SpelNodeImpl) ast;
}
Also used : SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression)

Example 14 with SpelNodeImpl

use of cn.taketoday.expression.spel.ast.SpelNodeImpl in project today-framework by TAKETODAY.

the class InternalSpelExpressionParser method eatPowerIncDecExpression.

// powerExpr  : unaryExpression (POWER^ unaryExpression)? (INC || DEC) ;
@Nullable
private SpelNodeImpl eatPowerIncDecExpression() {
    SpelNodeImpl expr = eatUnaryExpression();
    if (peekToken(TokenKind.POWER)) {
        // consume POWER
        Token t = takeToken();
        SpelNodeImpl rhExpr = eatUnaryExpression();
        checkRightOperand(t, rhExpr);
        return new OperatorPower(t.startPos, t.endPos, expr, rhExpr);
    }
    if (expr != null && peekToken(TokenKind.INC, TokenKind.DEC)) {
        // consume INC/DEC
        Token t = takeToken();
        if (t.kind == TokenKind.INC) {
            return new OpInc(t.startPos, t.endPos, true, expr);
        }
        return new OpDec(t.startPos, t.endPos, true, expr);
    }
    return expr;
}
Also used : OpInc(cn.taketoday.expression.spel.ast.OpInc) SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) OperatorPower(cn.taketoday.expression.spel.ast.OperatorPower) OpDec(cn.taketoday.expression.spel.ast.OpDec) Nullable(cn.taketoday.lang.Nullable)

Example 15 with SpelNodeImpl

use of cn.taketoday.expression.spel.ast.SpelNodeImpl in project today-framework by TAKETODAY.

the class InternalSpelExpressionParser method eatRelationalExpression.

// relationalExpression : sumExpression (relationalOperator^ sumExpression)?;
@Nullable
private SpelNodeImpl eatRelationalExpression() {
    SpelNodeImpl expr = eatSumExpression();
    Token relationalOperatorToken = maybeEatRelationalOperator();
    if (relationalOperatorToken != null) {
        // consume relational operator token
        Token t = takeToken();
        SpelNodeImpl rhExpr = eatSumExpression();
        checkOperands(t, expr, rhExpr);
        TokenKind tk = relationalOperatorToken.kind;
        if (relationalOperatorToken.isNumericRelationalOperator()) {
            if (tk == TokenKind.GT) {
                return new OpGT(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.LT) {
                return new OpLT(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.LE) {
                return new OpLE(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.GE) {
                return new OpGE(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.EQ) {
                return new OpEQ(t.startPos, t.endPos, expr, rhExpr);
            }
            Assert.isTrue(tk == TokenKind.NE, "Not-equals token expected");
            return new OpNE(t.startPos, t.endPos, expr, rhExpr);
        }
        if (tk == TokenKind.INSTANCEOF) {
            return new OperatorInstanceof(t.startPos, t.endPos, expr, rhExpr);
        }
        if (tk == TokenKind.MATCHES) {
            return new OperatorMatches(t.startPos, t.endPos, expr, rhExpr);
        }
        Assert.isTrue(tk == TokenKind.BETWEEN, "Between token expected");
        return new OperatorBetween(t.startPos, t.endPos, expr, rhExpr);
    }
    return expr;
}
Also used : SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) OperatorInstanceof(cn.taketoday.expression.spel.ast.OperatorInstanceof) OpEQ(cn.taketoday.expression.spel.ast.OpEQ) OpGE(cn.taketoday.expression.spel.ast.OpGE) OpGT(cn.taketoday.expression.spel.ast.OpGT) OpLT(cn.taketoday.expression.spel.ast.OpLT) OperatorMatches(cn.taketoday.expression.spel.ast.OperatorMatches) OpNE(cn.taketoday.expression.spel.ast.OpNE) OpLE(cn.taketoday.expression.spel.ast.OpLE) OperatorBetween(cn.taketoday.expression.spel.ast.OperatorBetween) Nullable(cn.taketoday.lang.Nullable)

Aggregations

SpelNodeImpl (cn.taketoday.expression.spel.ast.SpelNodeImpl)48 Nullable (cn.taketoday.lang.Nullable)18 PropertyOrFieldReference (cn.taketoday.expression.spel.ast.PropertyOrFieldReference)6 StandardEvaluationContext (cn.taketoday.expression.spel.support.StandardEvaluationContext)6 Test (org.junit.jupiter.api.Test)6 OpDec (cn.taketoday.expression.spel.ast.OpDec)4 OpInc (cn.taketoday.expression.spel.ast.OpInc)4 OpMinus (cn.taketoday.expression.spel.ast.OpMinus)4 OpPlus (cn.taketoday.expression.spel.ast.OpPlus)4 SpelExpression (cn.taketoday.expression.spel.standard.SpelExpression)4 ArrayList (java.util.ArrayList)4 InternalParseException (cn.taketoday.expression.spel.InternalParseException)2 SpelParseException (cn.taketoday.expression.spel.SpelParseException)2 Assign (cn.taketoday.expression.spel.ast.Assign)2 CompoundExpression (cn.taketoday.expression.spel.ast.CompoundExpression)2 ConstructorReference (cn.taketoday.expression.spel.ast.ConstructorReference)2 Elvis (cn.taketoday.expression.spel.ast.Elvis)2 FunctionReference (cn.taketoday.expression.spel.ast.FunctionReference)2 Identifier (cn.taketoday.expression.spel.ast.Identifier)2 Indexer (cn.taketoday.expression.spel.ast.Indexer)2