use of org.drools.mvelcompiler.ast.TypedExpression in project drools by kiegroup.
the class StatementVisitor method compileMVEL.
private TypedExpression compileMVEL(Node n) {
TypedExpression rhs = new RHSPhase(mvelCompilerContext).invoke(n);
TypedExpression lhs = new LHSPhase(mvelCompilerContext, ofNullable(rhs)).invoke(n);
Optional<TypedExpression> postProcessedRHS = new ReProcessRHSPhase(mvelCompilerContext).invoke(rhs, lhs);
TypedExpression postProcessedLHS = postProcessedRHS.map(ppr -> new LHSPhase(mvelCompilerContext, of(ppr)).invoke(n)).orElse(lhs);
return postProcessedLHS;
}
use of org.drools.mvelcompiler.ast.TypedExpression in project drools by kiegroup.
the class StatementVisitor method visit.
@Override
public TypedExpression visit(WhileStmt n, Void arg) {
TypedExpression typedCondition = new RHSPhase(mvelCompilerContext).invoke(n.getCondition());
TypedExpression typedThen = n.getBody().accept(this, arg);
return new WhileStmtT(typedCondition, typedThen);
}
use of org.drools.mvelcompiler.ast.TypedExpression in project drools by kiegroup.
the class StatementVisitor method visit.
@Override
public TypedExpression visit(SwitchStmt n, Void arg) {
TypedExpression typedSelector = new RHSPhase(mvelCompilerContext).invoke(n.getSelector());
List<TypedExpression> typedEntries = n.getEntries().stream().map(e -> e.accept(this, arg)).collect(Collectors.toList());
return new SwitchStmtT(typedSelector, typedEntries);
}
use of org.drools.mvelcompiler.ast.TypedExpression 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);
}
use of org.drools.mvelcompiler.ast.TypedExpression in project drools by kiegroup.
the class MvelCompiler method compileStatement.
public CompiledBlockResult compileStatement(String mvelBlock) {
BlockStmt mvelExpression = MvelParser.parseBlock(mvelBlock);
preprocessPhase.removeEmptyStmt(mvelExpression);
Set<String> allUsedBindings = new HashSet<>();
List<String> modifyUsedBindings = mvelExpression.findAll(ModifyStatement.class).stream().flatMap(this::transformStatementWithPreprocessing).collect(toList());
List<String> withUsedBindings = mvelExpression.findAll(WithStatement.class).stream().flatMap(this::transformStatementWithPreprocessing).collect(toList());
allUsedBindings.addAll(modifyUsedBindings);
allUsedBindings.addAll(withUsedBindings);
// Entry point of the compiler
TypedExpression compiledRoot = mvelExpression.accept(statementVisitor, null);
allUsedBindings.addAll(mvelCompilerContext.getUsedBindings());
Node javaRoot = compiledRoot.toJavaExpression();
if (!(javaRoot instanceof BlockStmt)) {
throw new MvelCompilerException("With a BlockStmt as a input I was expecting a BlockStmt output");
}
BlockStmt compiledBlockStatement = (BlockStmt) javaRoot;
return new CompiledBlockResult(compiledBlockStatement.getStatements()).setUsedBindings(allUsedBindings);
}
Aggregations