Search in sources :

Example 1 with ForEachStmtT

use of org.drools.mvelcompiler.ast.ForEachStmtT in project drools by kiegroup.

the class StatementVisitor method visit.

@Override
public TypedExpression visit(ForEachStmt n, Void arg) {
    Expression iterable = n.getIterable();
    Optional<TypedExpression> convertedToDowncastStmt = iterable.toNameExpr().map(PrintUtil::printNode).flatMap(mvelCompilerContext::findDeclarations).filter(this::isDeclarationIterable).map(d -> toForEachDowncastStmtT(n, arg));
    if (convertedToDowncastStmt.isPresent()) {
        return convertedToDowncastStmt.get();
    }
    TypedExpression variableDeclarationExpr = new LHSPhase(mvelCompilerContext, Optional.empty()).invoke(n.getVariable());
    TypedExpression typedIterable = new RHSPhase(mvelCompilerContext).invoke(n.getIterable());
    TypedExpression body = n.getBody().accept(this, arg);
    return new ForEachStmtT(variableDeclarationExpr, typedIterable, body);
}
Also used : UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) Expression(com.github.javaparser.ast.expr.Expression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression) ForEachStmtT(org.drools.mvelcompiler.ast.ForEachStmtT)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)1 ForEachStmtT (org.drools.mvelcompiler.ast.ForEachStmtT)1 TypedExpression (org.drools.mvelcompiler.ast.TypedExpression)1 UnalteredTypedExpression (org.drools.mvelcompiler.ast.UnalteredTypedExpression)1