use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class Consequence method executeCall.
private MethodCallExpr executeCall(BlockStmt ruleVariablesBlock, BlockStmt ruleConsequence, Collection<String> verifiedDeclUsedInRHS, MethodCallExpr onCall) {
boolean requireDrools = rewriteRHS(ruleVariablesBlock, ruleConsequence);
MethodCallExpr executeCall = new MethodCallExpr(onCall, EXECUTE_CALL);
LambdaExpr executeLambda = new LambdaExpr();
executeCall.addArgument(executeLambda);
executeLambda.setEnclosingParameters(true);
if (requireDrools) {
executeLambda.addParameter(new Parameter(new UnknownType(), "drools"));
}
verifiedDeclUsedInRHS.stream().map(x -> new Parameter(new UnknownType(), x)).forEach(executeLambda::addParameter);
executeLambda.setBody(ruleConsequence);
return executeCall;
}
use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class DrlxParseUtilTest method transformMethodExpressionToMethodCallExpressionTypeSafe.
@Test
public void transformMethodExpressionToMethodCallExpressionTypeSafe() {
final Expression expr = JavaParser.parseExpression("address.city.startsWith(\"M\")");
final Expression expr1 = JavaParser.parseExpression("getAddress().city.startsWith(\"M\")");
final Expression expr2 = JavaParser.parseExpression("address.getCity().startsWith(\"M\")");
final MethodCallExpr expected = JavaParser.parseExpression("getAddress().getCity().startsWith(\"M\")");
assertEquals(expected.toString(), DrlxParseUtil.toMethodCallWithClassCheck(null, expr, null, Person.class, typeResolver).getExpression().toString());
assertEquals(expected.toString(), DrlxParseUtil.toMethodCallWithClassCheck(null, expr1, null, Person.class, typeResolver).getExpression().toString());
assertEquals(expected.toString(), DrlxParseUtil.toMethodCallWithClassCheck(null, expr2, null, Person.class, typeResolver).getExpression().toString());
}
use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class PackageModel method addRulesList.
private void addRulesList(BlockStmt rulesListInitializerBody, String listName) {
MethodCallExpr add = new MethodCallExpr(new NameExpr("rules"), "addAll");
add.addArgument(listName);
rulesListInitializerBody.addStatement(add);
}
use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class PackageModel method addInitStatement.
private void addInitStatement(BlockStmt rulesListInitializerBody, Expression expr, String fieldName) {
NameExpr rulesFieldName = new NameExpr(fieldName);
MethodCallExpr add = new MethodCallExpr(rulesFieldName, "add");
add.addArgument(expr);
rulesListInitializerBody.addStatement(add);
}
use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class Consequence method onCall.
private static MethodCallExpr onCall(Collection<String> usedArguments) {
MethodCallExpr onCall = null;
if (!usedArguments.isEmpty()) {
onCall = new MethodCallExpr(null, ON_CALL);
usedArguments.stream().map(DrlxParseUtil::toVar).forEach(onCall::addArgument);
}
return onCall;
}
Aggregations