Search in sources :

Example 1 with PropertyOrFieldReference

use of cn.taketoday.expression.spel.ast.PropertyOrFieldReference in project today-infrastructure by TAKETODAY.

the class InternalSpelExpressionParser method maybeEatTypeReference.

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

Example 2 with PropertyOrFieldReference

use of cn.taketoday.expression.spel.ast.PropertyOrFieldReference in project today-infrastructure by TAKETODAY.

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

Example 3 with PropertyOrFieldReference

use of cn.taketoday.expression.spel.ast.PropertyOrFieldReference in project today-framework by TAKETODAY.

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

Example 4 with PropertyOrFieldReference

use of cn.taketoday.expression.spel.ast.PropertyOrFieldReference in project today-framework by TAKETODAY.

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
            var dimensions = new ArrayList<SpelNodeImpl>();
            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(cn.taketoday.expression.spel.ast.SpelNodeImpl) ArrayList(java.util.ArrayList) PropertyOrFieldReference(cn.taketoday.expression.spel.ast.PropertyOrFieldReference) ConstructorReference(cn.taketoday.expression.spel.ast.ConstructorReference)

Example 5 with PropertyOrFieldReference

use of cn.taketoday.expression.spel.ast.PropertyOrFieldReference in project today-framework by TAKETODAY.

the class InternalSpelExpressionParser method maybeEatTypeReference.

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

Aggregations

PropertyOrFieldReference (cn.taketoday.expression.spel.ast.PropertyOrFieldReference)6 SpelNodeImpl (cn.taketoday.expression.spel.ast.SpelNodeImpl)6 ConstructorReference (cn.taketoday.expression.spel.ast.ConstructorReference)2 MethodReference (cn.taketoday.expression.spel.ast.MethodReference)2 TypeReference (cn.taketoday.expression.spel.ast.TypeReference)2 ArrayList (java.util.ArrayList)2