use of org.drools.javaparser.ast.expr.LambdaExpr 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.LambdaExpr in project drools by kiegroup.
the class AccumulateVisitor method buildConstraintExpression.
protected Expression buildConstraintExpression(Expression expr, Collection<String> usedDeclarations) {
LambdaExpr lambdaExpr = new LambdaExpr();
lambdaExpr.setEnclosingParameters(true);
usedDeclarations.stream().map(s -> new Parameter(new UnknownType(), s)).forEach(lambdaExpr::addParameter);
lambdaExpr.setBody(new ExpressionStmt(expr));
return lambdaExpr;
}
use of org.drools.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class AccumulateVisitorFlowDSL method replaceBindingWithPatternBinding.
private void replaceBindingWithPatternBinding(MethodCallExpr bindExpression, MethodCallExpr lastPattern) {
if (lastPattern == null) {
return;
}
final Expression bindingId = lastPattern.getArgument(1);
bindExpression.findFirst(NameExpr.class, e -> e.equals(bindingId)).ifPresent(name -> {
LambdaExpr lambda = (LambdaExpr) bindExpression.getArgument(bindExpression.getArguments().size() - 1);
if (lambda.getParameters().size() > 1) {
String formalArg = fromVar(name.getNameAsString());
for (Parameter param : lambda.getParameters()) {
if (param.getNameAsString().equals(formalArg)) {
lambda.getParameters().remove(param);
lambda.getParameters().add(0, param);
break;
}
}
}
bindExpression.getArguments().remove(name);
bindExpression.getArguments().add(0, name);
});
}
use of org.drools.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class AccumulateVisitorPatternDSL method replaceBindingWithPatternBinding.
private MethodCallExpr replaceBindingWithPatternBinding(MethodCallExpr bindExpression, MethodCallExpr lastPattern) {
final Expression bindingId = lastPattern.getArgument(0);
bindExpression.findFirst(NameExpr.class, e -> e.equals(bindingId)).ifPresent(name -> {
bindExpression.remove(name);
LambdaExpr lambda = (LambdaExpr) bindExpression.getArgument(bindExpression.getArguments().size() - 1);
if (lambda.getParameters().size() > 1) {
String formalArg = fromVar(name.getNameAsString());
for (Parameter param : lambda.getParameters()) {
if (param.getNameAsString().equals(formalArg)) {
lambda.getParameters().remove(param);
lambda.getParameters().add(0, param);
break;
}
}
}
});
return (MethodCallExpr) bindExpression;
}
use of org.drools.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class DrlxParseUtil method generateLambdaWithoutParameters.
public static Expression generateLambdaWithoutParameters(Collection<String> usedDeclarations, Expression expr, boolean skipFirstParamAsThis) {
if (skipFirstParamAsThis && usedDeclarations.isEmpty()) {
return expr;
}
LambdaExpr lambdaExpr = new LambdaExpr();
lambdaExpr.setEnclosingParameters(true);
if (!skipFirstParamAsThis) {
lambdaExpr.addParameter(new Parameter(new UnknownType(), "_this"));
}
usedDeclarations.stream().map(s -> new Parameter(new UnknownType(), s)).forEach(lambdaExpr::addParameter);
lambdaExpr.setBody(new ExpressionStmt(expr));
return lambdaExpr;
}
Aggregations