use of org.drools.modelcompiler.builder.generator.DslMethodNames.REACT_ON_CALL 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);
});
}
Aggregations