use of org.drools.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class Consequence method executeScriptCall.
private MethodCallExpr executeScriptCall(RuleDescr ruleDescr, MethodCallExpr onCall) {
MethodCallExpr executeCall = new MethodCallExpr(onCall, EXECUTESCRIPT_CALL);
executeCall.addArgument(new StringLiteralExpr("mvel"));
ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr();
objectCreationExpr.setType(StringBuilder.class.getCanonicalName());
Expression mvelSB = objectCreationExpr;
for (String i : packageModel.getImports()) {
if (i.equals(packageModel.getName() + ".*")) {
// skip same-package star import.
continue;
}
MethodCallExpr appendCall = new MethodCallExpr(mvelSB, "append");
StringLiteralExpr importAsStringLiteral = new StringLiteralExpr();
// use the setter method in order for the string literal be properly escaped.
importAsStringLiteral.setString("import " + i + ";\n");
appendCall.addArgument(importAsStringLiteral);
mvelSB = appendCall;
}
StringLiteralExpr mvelScriptBodyStringLiteral = new StringLiteralExpr();
// use the setter method in order for the string literal be properly escaped.
mvelScriptBodyStringLiteral.setString(ruleDescr.getConsequence().toString());
MethodCallExpr appendCall = new MethodCallExpr(mvelSB, "append");
appendCall.addArgument(mvelScriptBodyStringLiteral);
executeCall.addArgument(new MethodCallExpr(appendCall, "toString"));
return executeCall;
}
Aggregations