Search in sources :

Example 1 with ConstructorReference

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

the class InternalSpelExpressionParser method maybeEatConstructorReference.

// constructor
// :	('new' qualifiedId LPAREN) => 'new' qualifiedId ctorArgs -> ^(CONSTRUCTOR qualifiedId ctorArgs)
private boolean maybeEatConstructorReference() {
    if (peekIdentifierToken("new")) {
        Token newToken = takeToken();
        // It looks like a constructor reference but is NEW being used as a map key?
        if (peekToken(TokenKind.RSQUARE)) {
            // looks like 'NEW]' (so NEW used as map key)
            push(new PropertyOrFieldReference(false, newToken.stringValue(), newToken.startPos, newToken.endPos));
            return true;
        }
        SpelNodeImpl possiblyQualifiedConstructorName = eatPossiblyQualifiedId();
        List<SpelNodeImpl> nodes = new ArrayList<>();
        nodes.add(possiblyQualifiedConstructorName);
        if (peekToken(TokenKind.LSQUARE)) {
            // array initializer
            List<SpelNodeImpl> dimensions = new ArrayList<>();
            while (peekToken(TokenKind.LSQUARE, true)) {
                if (!peekToken(TokenKind.RSQUARE)) {
                    dimensions.add(eatExpression());
                } else {
                    dimensions.add(null);
                }
                eatToken(TokenKind.RSQUARE);
            }
            if (maybeEatInlineListOrMap()) {
                nodes.add(pop());
            }
            push(new ConstructorReference(newToken.startPos, newToken.endPos, dimensions.toArray(new SpelNodeImpl[0]), nodes.toArray(new SpelNodeImpl[0])));
        } else {
            // regular constructor invocation
            eatConstructorArgs(nodes);
            // TODO correct end position?
            push(new ConstructorReference(newToken.startPos, newToken.endPos, nodes.toArray(new SpelNodeImpl[0])));
        }
        return true;
    }
    return false;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) ArrayList(java.util.ArrayList) PropertyOrFieldReference(org.springframework.expression.spel.ast.PropertyOrFieldReference) ConstructorReference(org.springframework.expression.spel.ast.ConstructorReference)

Aggregations

ArrayList (java.util.ArrayList)1 ConstructorReference (org.springframework.expression.spel.ast.ConstructorReference)1 PropertyOrFieldReference (org.springframework.expression.spel.ast.PropertyOrFieldReference)1 SpelNodeImpl (org.springframework.expression.spel.ast.SpelNodeImpl)1