use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class LambdaUtilTest method appendTwoMethodsToLambda.
@Test
public void appendTwoMethodsToLambda() {
LambdaExpr l1 = parseExpression("(_this) -> _this.getDueDate()");
LambdaExpr l2 = parseExpression("(_this) -> _this.getTime().getTime()");
Expression expected = parseExpression("(_this) -> _this.getDueDate().getTime().getTime()");
Expression actual = LambdaUtil.appendNewLambdaToOld(l1, l2);
assertEquals(expected.toString(), actual.toString());
}
use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class LambdaUtilTest method appendaLambdaToOld.
@Test
public void appendaLambdaToOld() {
LambdaExpr l1 = parseExpression("(_this) -> _this.getTimeFieldAsDate()");
LambdaExpr l2 = parseExpression("(_this) -> _this.getTime()");
Expression expected = parseExpression("(_this) -> _this.getTimeFieldAsDate().getTime()");
Expression actual = LambdaUtil.appendNewLambdaToOld(l1, l2);
assertEquals(expected.toString(), actual.toString());
}
use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class FromVisitor method fromConstructorExpr.
private Optional<Expression> fromConstructorExpr(String expression, ObjectCreationExpr parsedExpression) {
MethodCallExpr fromCall = createDslTopLevelMethod(FROM_CALL);
List<String> bindingIds = new ArrayList<>();
for (Expression argument : parsedExpression.getArguments()) {
final String argumentName = PrintUtil.printNode(argument);
if (contextHasDeclaration(argumentName)) {
bindingIds.add(argumentName);
fromCall.addArgument(context.getVarExpr(argumentName));
}
}
Expression newExpr = generateLambdaWithoutParameters(bindingIds, parsedExpression, true, Optional.empty(), context);
if (newExpr instanceof LambdaExpr) {
context.getPackageModel().registerLambdaReturnType((LambdaExpr) newExpr, DrlxParseUtil.getClassFromType(context.getTypeResolver(), parsedExpression.getType()));
}
fromCall.addArgument(newExpr);
return of(fromCall);
}
use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class AccumulateVisitor method composeTwoBindings.
private void composeTwoBindings(String binding, MethodCallExpr newBindingExpression) {
context.findBindingExpression(binding).ifPresent(oldBind -> {
// compose newComposedBinding using oldBind and newBindingExpression. But still keep oldBind.
LambdaExpr oldBindLambda = oldBind.findFirst(LambdaExpr.class).orElseThrow(RuntimeException::new);
LambdaExpr newBindLambda = newBindingExpression.findFirst(LambdaExpr.class).orElseThrow(RuntimeException::new);
LambdaExpr tmpOldBindLambda = oldBindLambda.clone();
Expression newComposedLambda = LambdaUtil.appendNewLambdaToOld(tmpOldBindLambda, newBindLambda);
MethodCallExpr newComposedBinding = new MethodCallExpr(BIND_CALL, newBindingExpression.getArgument(0), newComposedLambda);
newComposedBinding.setScope(oldBind.getScope().orElseThrow(RuntimeException::new));
Optional<MethodCallExpr> optReactOn = oldBind.getArguments().stream().filter(MethodCallExpr.class::isInstance).map(MethodCallExpr.class::cast).filter(exp -> exp.getName().asString().equals(REACT_ON_CALL)).findFirst();
if (optReactOn.isPresent()) {
newComposedBinding.addArgument(optReactOn.get().clone());
}
// insert newComposedBinding at the first in the chain
oldBind.setScope(newComposedBinding);
});
}
use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class FromVisitor method createSupplier.
private Expression createSupplier(Expression parsedExpression) {
final LambdaExpr lambdaExpr = new LambdaExpr(NodeList.nodeList(), new ExpressionStmt(parsedExpression), true);
MethodCallExpr fromCall = createDslTopLevelMethod(FROM_CALL);
fromCall.addArgument(lambdaExpr);
return fromCall;
}
Aggregations