Search in sources :

Example 1 with CompoundExpression

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();
}
Also used : SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) CompoundExpression(org.springframework.expression.spel.ast.CompoundExpression) Ternary(org.springframework.expression.spel.ast.Ternary) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) CompoundExpression(org.springframework.expression.spel.ast.CompoundExpression) OpLT(org.springframework.expression.spel.ast.OpLT) Test(org.junit.jupiter.api.Test)

Example 2 with CompoundExpression

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]));
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) CompoundExpression(org.springframework.expression.spel.ast.CompoundExpression) Nullable(org.springframework.lang.Nullable)

Aggregations

CompoundExpression (org.springframework.expression.spel.ast.CompoundExpression)2 Test (org.junit.jupiter.api.Test)1 Expression (org.springframework.expression.Expression)1 OpLT (org.springframework.expression.spel.ast.OpLT)1 SpelNodeImpl (org.springframework.expression.spel.ast.SpelNodeImpl)1 Ternary (org.springframework.expression.spel.ast.Ternary)1 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)1 Nullable (org.springframework.lang.Nullable)1