use of cn.taketoday.expression.spel.ast.SpelNodeImpl 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;
}
use of cn.taketoday.expression.spel.ast.SpelNodeImpl 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;
}
use of cn.taketoday.expression.spel.ast.SpelNodeImpl in project today-framework by TAKETODAY.
the class SpelCompilationCoverageTests method getAst.
// Helper methods
private SpelNodeImpl getAst() {
SpelExpression spelExpression = (SpelExpression) expression;
SpelNode ast = spelExpression.getAST();
return (SpelNodeImpl) ast;
}
use of cn.taketoday.expression.spel.ast.SpelNodeImpl in project today-framework by TAKETODAY.
the class InternalSpelExpressionParser method eatPowerIncDecExpression.
// powerExpr : unaryExpression (POWER^ unaryExpression)? (INC || DEC) ;
@Nullable
private SpelNodeImpl eatPowerIncDecExpression() {
SpelNodeImpl expr = eatUnaryExpression();
if (peekToken(TokenKind.POWER)) {
// consume POWER
Token t = takeToken();
SpelNodeImpl rhExpr = eatUnaryExpression();
checkRightOperand(t, rhExpr);
return new OperatorPower(t.startPos, t.endPos, expr, rhExpr);
}
if (expr != null && peekToken(TokenKind.INC, TokenKind.DEC)) {
// consume INC/DEC
Token t = takeToken();
if (t.kind == TokenKind.INC) {
return new OpInc(t.startPos, t.endPos, true, expr);
}
return new OpDec(t.startPos, t.endPos, true, expr);
}
return expr;
}
use of cn.taketoday.expression.spel.ast.SpelNodeImpl in project today-framework by TAKETODAY.
the class InternalSpelExpressionParser method eatRelationalExpression.
// relationalExpression : sumExpression (relationalOperator^ sumExpression)?;
@Nullable
private SpelNodeImpl eatRelationalExpression() {
SpelNodeImpl expr = eatSumExpression();
Token relationalOperatorToken = maybeEatRelationalOperator();
if (relationalOperatorToken != null) {
// consume relational operator token
Token t = takeToken();
SpelNodeImpl rhExpr = eatSumExpression();
checkOperands(t, expr, rhExpr);
TokenKind tk = relationalOperatorToken.kind;
if (relationalOperatorToken.isNumericRelationalOperator()) {
if (tk == TokenKind.GT) {
return new OpGT(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.LT) {
return new OpLT(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.LE) {
return new OpLE(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.GE) {
return new OpGE(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.EQ) {
return new OpEQ(t.startPos, t.endPos, expr, rhExpr);
}
Assert.isTrue(tk == TokenKind.NE, "Not-equals token expected");
return new OpNE(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.INSTANCEOF) {
return new OperatorInstanceof(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.MATCHES) {
return new OperatorMatches(t.startPos, t.endPos, expr, rhExpr);
}
Assert.isTrue(tk == TokenKind.BETWEEN, "Between token expected");
return new OperatorBetween(t.startPos, t.endPos, expr, rhExpr);
}
return expr;
}
Aggregations