Search in sources :

Example 6 with SpelNodeImpl

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

the class InternalSpelExpressionParser method maybeEatSelection.

private boolean maybeEatSelection(boolean nullSafeNavigation) {
    Token t = peekToken();
    if (!peekSelectToken()) {
        return false;
    }
    nextToken();
    SpelNodeImpl expr = eatExpression();
    if (expr == null) {
        raiseInternalException(toPos(t), SpelMessage.MISSING_SELECTION_EXPRESSION);
    }
    eatToken(TokenKind.RSQUARE);
    if (t.kind == TokenKind.SELECT_FIRST) {
        this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.FIRST, toPos(t), expr));
    } else if (t.kind == TokenKind.SELECT_LAST) {
        this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.LAST, toPos(t), expr));
    } else {
        this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.ALL, toPos(t), expr));
    }
    return true;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) Selection(org.springframework.expression.spel.ast.Selection)

Example 7 with SpelNodeImpl

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

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 = nextToken();
        SpelNodeImpl[] args = maybeEatMethodArgs();
        if (args == null) {
            // property
            push(new PropertyOrFieldReference(nullSafeNavigation, methodOrPropertyName.data, toPos(methodOrPropertyName)));
            return true;
        }
        // method reference
        push(new MethodReference(nullSafeNavigation, methodOrPropertyName.data, toPos(methodOrPropertyName), args));
        // TODO what is the end position for a method reference? the name or the last arg?
        return true;
    }
    return false;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) MethodReference(org.springframework.expression.spel.ast.MethodReference) PropertyOrFieldReference(org.springframework.expression.spel.ast.PropertyOrFieldReference)

Example 8 with SpelNodeImpl

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

the class InternalSpelExpressionParser method eatLogicalOrExpression.

//logicalOrExpression : logicalAndExpression (OR^ logicalAndExpression)*;
private SpelNodeImpl eatLogicalOrExpression() {
    SpelNodeImpl expr = eatLogicalAndExpression();
    while (peekIdentifierToken("or") || peekToken(TokenKind.SYMBOLIC_OR)) {
        //consume OR
        Token t = nextToken();
        SpelNodeImpl rhExpr = eatLogicalAndExpression();
        checkOperands(t, expr, rhExpr);
        expr = new OpOr(toPos(t), expr, rhExpr);
    }
    return expr;
}
Also used : OpOr(org.springframework.expression.spel.ast.OpOr) SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl)

Example 9 with SpelNodeImpl

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

the class InternalSpelExpressionParser method maybeEatTypeReference.

private boolean maybeEatTypeReference() {
    if (peekToken(TokenKind.IDENTIFIER)) {
        Token typeName = peekToken();
        if (!"T".equals(typeName.stringValue())) {
            return false;
        }
        // It looks like a type reference but is T being used as a map key?
        Token t = nextToken();
        if (peekToken(TokenKind.RSQUARE)) {
            // looks like 'T]' (T is map key)
            push(new PropertyOrFieldReference(false, t.data, toPos(t)));
            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(toPos(typeName), node, dims));
        return true;
    }
    return false;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) PropertyOrFieldReference(org.springframework.expression.spel.ast.PropertyOrFieldReference) TypeReference(org.springframework.expression.spel.ast.TypeReference)

Example 10 with SpelNodeImpl

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

the class InternalSpelExpressionParser method maybeEatProjection.

//projection: PROJECT^ expression RCURLY!;
private boolean maybeEatProjection(boolean nullSafeNavigation) {
    Token t = peekToken();
    if (!peekToken(TokenKind.PROJECT, true)) {
        return false;
    }
    SpelNodeImpl expr = eatExpression();
    eatToken(TokenKind.RSQUARE);
    this.constructedNodes.push(new Projection(nullSafeNavigation, toPos(t), expr));
    return true;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) Projection(org.springframework.expression.spel.ast.Projection)

Aggregations

SpelNodeImpl (org.springframework.expression.spel.ast.SpelNodeImpl)21 ArrayList (java.util.ArrayList)3 PropertyOrFieldReference (org.springframework.expression.spel.ast.PropertyOrFieldReference)3 LinkedList (java.util.LinkedList)2 OpDec (org.springframework.expression.spel.ast.OpDec)2 OpInc (org.springframework.expression.spel.ast.OpInc)2 OpMinus (org.springframework.expression.spel.ast.OpMinus)2 OpPlus (org.springframework.expression.spel.ast.OpPlus)2 List (java.util.List)1 InternalParseException (org.springframework.expression.spel.InternalParseException)1 SpelParseException (org.springframework.expression.spel.SpelParseException)1 Assign (org.springframework.expression.spel.ast.Assign)1 CompoundExpression (org.springframework.expression.spel.ast.CompoundExpression)1 ConstructorReference (org.springframework.expression.spel.ast.ConstructorReference)1 Elvis (org.springframework.expression.spel.ast.Elvis)1 FunctionReference (org.springframework.expression.spel.ast.FunctionReference)1 Identifier (org.springframework.expression.spel.ast.Identifier)1 Indexer (org.springframework.expression.spel.ast.Indexer)1 InlineList (org.springframework.expression.spel.ast.InlineList)1 InlineMap (org.springframework.expression.spel.ast.InlineMap)1