use of org.drools.modelcompiler.builder.generator.drlxparse.CoercedExpression in project drools by kiegroup.
the class NativeOperatorSpec method getExpression.
public Expression getExpression(RuleContext context, PointFreeExpr pointFreeExpr, TypedExpression left, ExpressionTyper expressionTyper) {
MethodCallExpr methodCallExpr = createDslTopLevelMethod(EVAL_CALL);
String opName = pointFreeExpr.getOperator().asString();
Operator operator = addOperatorArgument(context, methodCallExpr, opName);
if (operator != null && !operator.isCompatibleWithType(left.getRawClass())) {
context.addCompilationError(new InvalidExpressionErrorResult("Cannot use contains on class " + left.getRawClass() + " in expression '" + PrintUtil.printNode(pointFreeExpr) + "'"));
}
methodCallExpr.addArgument(left.getExpression());
for (Expression rightExpr : pointFreeExpr.getRight()) {
final Optional<TypedExpression> optionalRight = expressionTyper.toTypedExpression(rightExpr).getTypedExpression();
optionalRight.ifPresent(right -> {
final TypedExpression coercedRight;
if (operator != null && operator.requiresCoercion()) {
final CoercedExpression.CoercedExpressionResult coerced = new CoercedExpression(left, right, false).coerce();
coercedRight = getCoercedRightExpression(context.getPackageModel(), coerced);
} else {
coercedRight = right;
}
methodCallExpr.addArgument(coercedRight.getExpression());
});
}
return pointFreeExpr.isNegated() ? new UnaryExpr(methodCallExpr, UnaryExpr.Operator.LOGICAL_COMPLEMENT) : methodCallExpr;
}
Aggregations