Search in sources :

Example 1 with NullLiteral

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

the class InternalSpelExpressionParser method maybeEatNullReference.

private boolean maybeEatNullReference() {
    if (peekToken(TokenKind.IDENTIFIER)) {
        Token nullToken = peekToken();
        if (!"null".equalsIgnoreCase(nullToken.stringValue())) {
            return false;
        }
        nextToken();
        this.constructedNodes.push(new NullLiteral(toPos(nullToken)));
        return true;
    }
    return false;
}
Also used : NullLiteral(org.springframework.expression.spel.ast.NullLiteral)

Example 2 with NullLiteral

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

the class InternalSpelExpressionParser method eatExpression.

//	expression
//    : logicalOrExpression
//      ( (ASSIGN^ logicalOrExpression)
//	    | (DEFAULT^ logicalOrExpression)
//	    | (QMARK^ expression COLON! expression)
//      | (ELVIS^ expression))?;
private SpelNodeImpl eatExpression() {
    SpelNodeImpl expr = eatLogicalOrExpression();
    if (moreTokens()) {
        Token t = peekToken();
        if (t.kind == TokenKind.ASSIGN) {
            // a=b
            if (expr == null) {
                expr = new NullLiteral(toPos(t.startPos - 1, t.endPos - 1));
            }
            nextToken();
            SpelNodeImpl assignedValue = eatLogicalOrExpression();
            return new Assign(toPos(t), expr, assignedValue);
        }
        if (t.kind == TokenKind.ELVIS) {
            // a?:b (a if it isn't null, otherwise b)
            if (expr == null) {
                expr = new NullLiteral(toPos(t.startPos - 1, t.endPos - 2));
            }
            // elvis has left the building
            nextToken();
            SpelNodeImpl valueIfNull = eatExpression();
            if (valueIfNull == null) {
                valueIfNull = new NullLiteral(toPos(t.startPos + 1, t.endPos + 1));
            }
            return new Elvis(toPos(t), expr, valueIfNull);
        }
        if (t.kind == TokenKind.QMARK) {
            // a?b:c
            if (expr == null) {
                expr = new NullLiteral(toPos(t.startPos - 1, t.endPos - 1));
            }
            nextToken();
            SpelNodeImpl ifTrueExprValue = eatExpression();
            eatToken(TokenKind.COLON);
            SpelNodeImpl ifFalseExprValue = eatExpression();
            return new Ternary(toPos(t), expr, ifTrueExprValue, ifFalseExprValue);
        }
    }
    return expr;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) Ternary(org.springframework.expression.spel.ast.Ternary) Elvis(org.springframework.expression.spel.ast.Elvis) Assign(org.springframework.expression.spel.ast.Assign) NullLiteral(org.springframework.expression.spel.ast.NullLiteral)

Aggregations

NullLiteral (org.springframework.expression.spel.ast.NullLiteral)2 Assign (org.springframework.expression.spel.ast.Assign)1 Elvis (org.springframework.expression.spel.ast.Elvis)1 SpelNodeImpl (org.springframework.expression.spel.ast.SpelNodeImpl)1 Ternary (org.springframework.expression.spel.ast.Ternary)1