use of com.github.javaparser.ast.Node in project drools by kiegroup.
the class FlattenScopeTest method expr.
private Expression expr(String inputExpr) {
Expression expr = DrlxParseUtil.parseExpression(inputExpr).getExpr();
// This is because parsing doesn't set type arguments.
expr.ifMethodCallExpr(m -> m.setTypeArguments(nodeList()));
expr.getChildNodes().forEach((Node e) -> {
if (e instanceof Expression) {
((Expression) e).ifMethodCallExpr(m -> m.setTypeArguments(nodeList()));
}
});
return expr;
}
use of com.github.javaparser.ast.Node in project drools by kiegroup.
the class FlattenScopeTest method flattenUnaryExpression.
@Test
public void flattenUnaryExpression() {
List<Node> actual = flattenScope(MockTypeResolver.INSTANCE, expr("getMessageId"));
List<Node> expected = Collections.singletonList(new NameExpr("getMessageId"));
compareArrays(actual, expected);
}
use of com.github.javaparser.ast.Node in project drools by kiegroup.
the class ModifyCompiler method compile.
public CompiledBlockResult compile(String mvelBlock) {
BlockStmt mvelExpression = MvelParser.parseBlock(mvelBlock);
preprocessPhase.removeEmptyStmt(mvelExpression);
Set<String> usedBindings = new HashSet<>();
mvelExpression.findAll(ModifyStatement.class).forEach(s -> {
Optional<Node> parentNode = s.getParentNode();
PreprocessPhase.PreprocessPhaseResult invoke = preprocessPhase.invoke(s);
usedBindings.addAll(invoke.getUsedBindings());
parentNode.ifPresent(p -> {
BlockStmt parentBlock = (BlockStmt) p;
for (String modifiedFact : invoke.getUsedBindings()) {
parentBlock.addStatement(new MethodCallExpr(null, "update", nodeList(new NameExpr(modifiedFact))));
}
});
s.remove();
});
return new CompiledBlockResult(mvelExpression.getStatements()).setUsedBindings(usedBindings);
}
use of com.github.javaparser.ast.Node 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 com.github.javaparser.ast.Node 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