Search in sources :

Example 1 with OpLT

use of org.springframework.expression.spel.ast.OpLT in project spring-framework by spring-projects.

the class SpelCompilationCoverageTests method mixingItUp_propertyAccessIndexerOpLtTernaryRootNull.

@Test
void mixingItUp_propertyAccessIndexerOpLtTernaryRootNull() {
    Payload payload = new Payload();
    expression = parser.parseExpression("DR[0].three");
    Object v = expression.getValue(payload);
    assertThat(getAst().getExitDescriptor()).isEqualTo("Lorg/springframework/expression/spel/SpelCompilationCoverageTests$Three");
    Expression expression = parser.parseExpression("DR[0].three.four lt 0.1d?#root:null");
    v = expression.getValue(payload);
    SpelExpression sExpr = (SpelExpression) expression;
    Ternary ternary = (Ternary) sExpr.getAST();
    OpLT oplt = (OpLT) ternary.getChild(0);
    CompoundExpression cExpr = (CompoundExpression) oplt.getLeftOperand();
    String cExprExitDescriptor = cExpr.getExitDescriptor();
    assertThat(cExprExitDescriptor).isEqualTo("D");
    assertThat(oplt.getExitDescriptor()).isEqualTo("Z");
    assertCanCompile(expression);
    Object vc = expression.getValue(payload);
    assertThat(v).isEqualTo(payload);
    assertThat(vc).isEqualTo(payload);
    payload.DR[0].three.four = 0.13d;
    vc = expression.getValue(payload);
    assertThat(vc).isNull();
}
Also used : SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) CompoundExpression(org.springframework.expression.spel.ast.CompoundExpression) Ternary(org.springframework.expression.spel.ast.Ternary) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) CompoundExpression(org.springframework.expression.spel.ast.CompoundExpression) OpLT(org.springframework.expression.spel.ast.OpLT) Test(org.junit.jupiter.api.Test)

Example 2 with OpLT

use of org.springframework.expression.spel.ast.OpLT in project spring-framework by spring-projects.

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(org.springframework.expression.spel.ast.SpelNodeImpl) OperatorInstanceof(org.springframework.expression.spel.ast.OperatorInstanceof) OpEQ(org.springframework.expression.spel.ast.OpEQ) OpGE(org.springframework.expression.spel.ast.OpGE) OpGT(org.springframework.expression.spel.ast.OpGT) OpLT(org.springframework.expression.spel.ast.OpLT) OperatorMatches(org.springframework.expression.spel.ast.OperatorMatches) OpNE(org.springframework.expression.spel.ast.OpNE) OpLE(org.springframework.expression.spel.ast.OpLE) OperatorBetween(org.springframework.expression.spel.ast.OperatorBetween) Nullable(org.springframework.lang.Nullable)

Aggregations

OpLT (org.springframework.expression.spel.ast.OpLT)2 Test (org.junit.jupiter.api.Test)1 Expression (org.springframework.expression.Expression)1 CompoundExpression (org.springframework.expression.spel.ast.CompoundExpression)1 OpEQ (org.springframework.expression.spel.ast.OpEQ)1 OpGE (org.springframework.expression.spel.ast.OpGE)1 OpGT (org.springframework.expression.spel.ast.OpGT)1 OpLE (org.springframework.expression.spel.ast.OpLE)1 OpNE (org.springframework.expression.spel.ast.OpNE)1 OperatorBetween (org.springframework.expression.spel.ast.OperatorBetween)1 OperatorInstanceof (org.springframework.expression.spel.ast.OperatorInstanceof)1 OperatorMatches (org.springframework.expression.spel.ast.OperatorMatches)1 SpelNodeImpl (org.springframework.expression.spel.ast.SpelNodeImpl)1 Ternary (org.springframework.expression.spel.ast.Ternary)1 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)1 Nullable (org.springframework.lang.Nullable)1