use of org.springframework.expression.spel.ast.InlineList in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method maybeEatInlineListOrMap.
// list = LCURLY (element (COMMA element)*) RCURLY
// map = LCURLY (key ':' value (COMMA key ':' value)*) RCURLY
private boolean maybeEatInlineListOrMap() {
Token t = peekToken();
if (!peekToken(TokenKind.LCURLY, true)) {
return false;
}
SpelNodeImpl expr = null;
Token closingCurly = peekToken();
if (peekToken(TokenKind.RCURLY, true)) {
// empty list '{}'
expr = new InlineList(toPos(t.startPos, closingCurly.endPos));
} else if (peekToken(TokenKind.COLON, true)) {
closingCurly = eatToken(TokenKind.RCURLY);
// empty map '{:}'
expr = new InlineMap(toPos(t.startPos, closingCurly.endPos));
} else {
SpelNodeImpl firstExpression = eatExpression();
// ':' - this is a map!
if (peekToken(TokenKind.RCURLY)) {
// list with one item in it
List<SpelNodeImpl> listElements = new ArrayList<>();
listElements.add(firstExpression);
closingCurly = eatToken(TokenKind.RCURLY);
expr = new InlineList(toPos(t.startPos, closingCurly.endPos), listElements.toArray(new SpelNodeImpl[listElements.size()]));
} else if (peekToken(TokenKind.COMMA, true)) {
// multi-item list
List<SpelNodeImpl> listElements = new ArrayList<>();
listElements.add(firstExpression);
do {
listElements.add(eatExpression());
} while (peekToken(TokenKind.COMMA, true));
closingCurly = eatToken(TokenKind.RCURLY);
expr = new InlineList(toPos(t.startPos, closingCurly.endPos), listElements.toArray(new SpelNodeImpl[listElements.size()]));
} else if (peekToken(TokenKind.COLON, true)) {
// map!
List<SpelNodeImpl> mapElements = new ArrayList<>();
mapElements.add(firstExpression);
mapElements.add(eatExpression());
while (peekToken(TokenKind.COMMA, true)) {
mapElements.add(eatExpression());
eatToken(TokenKind.COLON);
mapElements.add(eatExpression());
}
closingCurly = eatToken(TokenKind.RCURLY);
expr = new InlineMap(toPos(t.startPos, closingCurly.endPos), mapElements.toArray(new SpelNodeImpl[mapElements.size()]));
} else {
raiseInternalException(t.startPos, SpelMessage.OOD);
}
}
this.constructedNodes.push(expr);
return true;
}
use of org.springframework.expression.spel.ast.InlineList in project spring-framework by spring-projects.
the class ListTests method checkConstantList.
private void checkConstantList(String expressionText, boolean expectedToBeConstant) {
SpelExpressionParser parser = new SpelExpressionParser();
SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
SpelNode node = expression.getAST();
assertTrue(node instanceof InlineList);
InlineList inlineList = (InlineList) node;
if (expectedToBeConstant) {
assertTrue(inlineList.isConstant());
} else {
assertFalse(inlineList.isConstant());
}
}
Aggregations