Search in sources :

Example 1 with CompoundExpression

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

the class InternalSpelExpressionParser method eatPrimaryExpression.

// primaryExpression : startNode (node)? -> ^(EXPRESSION startNode (node)?);
@Nullable
private SpelNodeImpl eatPrimaryExpression() {
    // always a start node
    SpelNodeImpl start = eatStartNode();
    ArrayList<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(cn.taketoday.expression.spel.ast.SpelNodeImpl) CompoundExpression(cn.taketoday.expression.spel.ast.CompoundExpression) Nullable(cn.taketoday.lang.Nullable)

Example 2 with CompoundExpression

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

the class InternalSpelExpressionParser method eatPrimaryExpression.

// primaryExpression : startNode (node)? -> ^(EXPRESSION startNode (node)?);
@Nullable
private SpelNodeImpl eatPrimaryExpression() {
    // always a start node
    SpelNodeImpl start = eatStartNode();
    ArrayList<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(cn.taketoday.expression.spel.ast.SpelNodeImpl) CompoundExpression(cn.taketoday.expression.spel.ast.CompoundExpression) Nullable(cn.taketoday.lang.Nullable)

Example 3 with CompoundExpression

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

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("Lcn/taketoday/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 : Expression(cn.taketoday.expression.Expression) CompoundExpression(cn.taketoday.expression.spel.ast.CompoundExpression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) Ternary(cn.taketoday.expression.spel.ast.Ternary) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) CompoundExpression(cn.taketoday.expression.spel.ast.CompoundExpression) OpLT(cn.taketoday.expression.spel.ast.OpLT) Test(org.junit.jupiter.api.Test)

Example 4 with CompoundExpression

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

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("Lcn/taketoday/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 : Expression(cn.taketoday.expression.Expression) CompoundExpression(cn.taketoday.expression.spel.ast.CompoundExpression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) Ternary(cn.taketoday.expression.spel.ast.Ternary) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) CompoundExpression(cn.taketoday.expression.spel.ast.CompoundExpression) OpLT(cn.taketoday.expression.spel.ast.OpLT) Test(org.junit.jupiter.api.Test)

Aggregations

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