Search in sources :

Example 1 with BigDecimalArgumentCoercion

use of org.drools.mvelcompiler.util.BigDecimalArgumentCoercion in project drools by kiegroup.

the class ExpressionTyper method promoteBigDecimalParameters.

private void promoteBigDecimalParameters(MethodCallExpr methodCallExpr, Class[] argsType, Class<?>[] actualArgumentTypes) {
    if (actualArgumentTypes.length == argsType.length && actualArgumentTypes.length == methodCallExpr.getArguments().size()) {
        for (int i = 0; i < argsType.length; i++) {
            Class<?> argumentType = argsType[i];
            Class<?> actualArgumentType = actualArgumentTypes[i];
            Expression argumentExpression = methodCallExpr.getArgument(i);
            if (argumentType != actualArgumentType) {
                Expression coercedExpression = new BigDecimalArgumentCoercion().coercedArgument(argumentType, actualArgumentType, argumentExpression);
                methodCallExpr.setArgument(i, coercedExpression);
            }
        }
    }
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) UnificationTypedExpression(org.drools.modelcompiler.builder.generator.UnificationTypedExpression) MapCreationLiteralExpression(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression) DrlxParseUtil.isThisExpression(org.drools.modelcompiler.builder.generator.DrlxParseUtil.isThisExpression) ListCreationLiteralExpression(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) BigDecimalArgumentCoercion(org.drools.mvelcompiler.util.BigDecimalArgumentCoercion)

Example 2 with BigDecimalArgumentCoercion

use of org.drools.mvelcompiler.util.BigDecimalArgumentCoercion in project drools by kiegroup.

the class MethodCallExprT method toJavaArgument.

private Expression toJavaArgument(List<TypedExpression> typedExpressions, int i) {
    TypedExpression a = typedExpressions.get(i);
    Optional<Class<?>> optionalActualType = Optional.empty();
    if (actualMethodArgumentType.size() == typedExpressions.size()) {
        optionalActualType = Optional.ofNullable(actualMethodArgumentType.get(i));
    }
    if (optionalActualType.isPresent() && a.getType().isPresent()) {
        Type argumentTypeOrig = a.getType().get();
        if (argumentTypeOrig instanceof Class) {
            Class<?> argumentType = (Class<?>) argumentTypeOrig;
            Class<?> actualType = optionalActualType.get();
            if (argumentType != actualType) {
                return new BigDecimalArgumentCoercion().coercedArgument(argumentType, actualType, (Expression) a.toJavaExpression());
            }
        }
    }
    return (Expression) a.toJavaExpression();
}
Also used : Type(java.lang.reflect.Type) Expression(com.github.javaparser.ast.expr.Expression) BigDecimalArgumentCoercion(org.drools.mvelcompiler.util.BigDecimalArgumentCoercion)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)2 BigDecimalArgumentCoercion (org.drools.mvelcompiler.util.BigDecimalArgumentCoercion)2 Type (java.lang.reflect.Type)1 DrlxParseUtil.isThisExpression (org.drools.modelcompiler.builder.generator.DrlxParseUtil.isThisExpression)1 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)1 UnificationTypedExpression (org.drools.modelcompiler.builder.generator.UnificationTypedExpression)1 ListCreationLiteralExpression (org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression)1 MapCreationLiteralExpression (org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression)1