Search in sources :

Example 1 with PropertyOrFieldReference

use of org.springframework.expression.spel.ast.PropertyOrFieldReference 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 = nextToken();
        // 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.data, toPos(newToken)));
            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(toPos(newToken), dimensions.toArray(new SpelNodeImpl[dimensions.size()]), nodes.toArray(new SpelNodeImpl[nodes.size()])));
        } else {
            // regular constructor invocation
            eatConstructorArgs(nodes);
            // TODO correct end position?
            push(new ConstructorReference(toPos(newToken), nodes.toArray(new SpelNodeImpl[nodes.size()])));
        }
        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)

Example 2 with PropertyOrFieldReference

use of org.springframework.expression.spel.ast.PropertyOrFieldReference 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 3 with PropertyOrFieldReference

use of org.springframework.expression.spel.ast.PropertyOrFieldReference 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)

Aggregations

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