use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class Query method createFromExpr.
private MethodCallExpr createFromExpr(String variableName, Expression expr) {
MethodCallExpr dslExpr = createDslTopLevelMethod(PATTERN_CALL);
dslExpr.addArgument(context.getVarExpr(variableName));
context.addExpression(dslExpr);
MethodCallExpr fromExpr = createDslTopLevelMethod(FROM_CALL);
LambdaExpr lambdaExpr = new LambdaExpr();
lambdaExpr.setEnclosingParameters(true);
TypedExpressionResult result = new ExpressionTyper(context).toTypedExpression(expr);
for (String usedDeclration : result.getExpressionTyperContext().getUsedDeclarations()) {
fromExpr.addArgument(context.getVarExpr(usedDeclration));
lambdaExpr.addParameter(new Parameter(context.getDelarationType(usedDeclration), usedDeclration));
}
fromExpr.addArgument(lambdaExpr);
if (result.getTypedExpression().isPresent()) {
lambdaExpr.setBody(new ExpressionStmt(result.getTypedExpression().get().getExpression()));
}
return fromExpr;
}
use of com.github.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, Set<String> modifyProperties) {
for (String modifiedProperty : modifyProperties) {
NodeList<Expression> arguments = nodeList(new NameExpr(modifiedProperty));
MethodCallExpr update = new MethodCallExpr(new NameExpr("drools"), "update", arguments);
ruleConsequence.getStatements().add(new ExpressionStmt(update));
}
boolean requireDrools = rewriteRHS(ruleVariablesBlock, ruleConsequence);
MethodCallExpr executeCall = new MethodCallExpr(onCall != null ? onCall : new NameExpr("D"), EXECUTE_CALL);
LambdaExpr executeLambda = new LambdaExpr();
executeCall.addArgument(executeLambda);
executeLambda.setEnclosingParameters(true);
if (requireDrools) {
executeLambda.addParameter(new Parameter(toClassOrInterfaceType(org.drools.model.Drools.class), "drools"));
}
NodeList<Parameter> parameters = new BoxedParameters(context).getBoxedParametersWithUnboxedAssignment(verifiedDeclUsedInRHS, ruleConsequence);
parameters.forEach(executeLambda::addParameter);
executeLambda.setBody(ruleConsequence);
return executeCall;
}
use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class Expressions method namedUnaryLambda.
public static NamedLambda namedUnaryLambda(Expression expr, String text) {
LambdaExpr lambda = Expressions.unaryLambda(expr);
String name = Constants.unaryTestName(text);
FieldDeclaration field = Constants.unaryTest(name, lambda);
return new NamedLambda(new NameExpr(name), lambda, field);
}
use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class Expressions method namedLambda.
public static NamedLambda namedLambda(Expression expr, String text) {
LambdaExpr lambda = Expressions.lambda(expr);
String name = Constants.functionName(text);
FieldDeclaration field = Constants.function(name, lambda);
return new NamedLambda(new NameExpr(name), lambda, field);
}
use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class Functions method declaration.
public static DirectCompilerResult declaration(FunctionDefNode n, MethodCallExpr list, Expression fnBody) {
LambdaExpr lambda = Expressions.lambda(fnBody);
String fnName = Constants.functionName(n.getBody().getText());
DirectCompilerResult r = DirectCompilerResult.of(Functions.internal(list, new NameExpr(fnName)), BuiltInType.FUNCTION);
r.addFieldDeclaration(Constants.function(fnName, lambda));
return r;
}
Aggregations