use of org.springframework.expression.spel.ast.CompoundExpression in project spring-framework by spring-projects.
the class SpelCompilationCoverageTests method mixingItUp_propertyAccessIndexerOpLtTernaryRootNull.
@Test
void mixingItUp_propertyAccessIndexerOpLtTernaryRootNull() {
Payload payload = new Payload();
expression = parser.parseExpression("DR[0].three");
Object v = expression.getValue(payload);
assertThat(getAst().getExitDescriptor()).isEqualTo("Lorg/springframework/expression/spel/SpelCompilationCoverageTests$Three");
Expression expression = parser.parseExpression("DR[0].three.four lt 0.1d?#root:null");
v = expression.getValue(payload);
SpelExpression sExpr = (SpelExpression) expression;
Ternary ternary = (Ternary) sExpr.getAST();
OpLT oplt = (OpLT) ternary.getChild(0);
CompoundExpression cExpr = (CompoundExpression) oplt.getLeftOperand();
String cExprExitDescriptor = cExpr.getExitDescriptor();
assertThat(cExprExitDescriptor).isEqualTo("D");
assertThat(oplt.getExitDescriptor()).isEqualTo("Z");
assertCanCompile(expression);
Object vc = expression.getValue(payload);
assertThat(v).isEqualTo(payload);
assertThat(vc).isEqualTo(payload);
payload.DR[0].three.four = 0.13d;
vc = expression.getValue(payload);
assertThat(vc).isNull();
}
use of org.springframework.expression.spel.ast.CompoundExpression in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method eatPrimaryExpression.
// primaryExpression : startNode (node)? -> ^(EXPRESSION startNode (node)?);
@Nullable
private SpelNodeImpl eatPrimaryExpression() {
// always a start node
SpelNodeImpl start = eatStartNode();
List<SpelNodeImpl> nodes = null;
SpelNodeImpl node = eatNode();
while (node != null) {
if (nodes == null) {
nodes = new ArrayList<>(4);
nodes.add(start);
}
nodes.add(node);
node = eatNode();
}
if (start == null || nodes == null) {
return start;
}
return new CompoundExpression(start.getStartPosition(), nodes.get(nodes.size() - 1).getEndPosition(), nodes.toArray(new SpelNodeImpl[0]));
}
Aggregations