use of org.drools.mvelcompiler.ast.AssignExprT in project drools by kiegroup.
the class LHSPhase method withBigDecimalConversion.
// Conversion of AssignExpr to BigDecimal Arithmetic operation when LHS is is a BigDecimal variable
public Optional<TypedExpression> withBigDecimalConversion(AssignExpr assignExpr, TypedExpression target, TypedExpression value) {
Optional<Type> optRHSType = value.getType();
if (!optRHSType.isPresent()) {
return Optional.empty();
}
AssignExpr.Operator operator = assignExpr.getOperator();
if (operator == AssignExpr.Operator.ASSIGN) {
return Optional.empty();
}
// handled previously in FieldAccessExpr visitor
boolean assigningToFieldAccess = target instanceof FieldToAccessorTExpr;
if (!assigningToFieldAccess && target.getType().filter(t -> t == BigDecimal.class).isPresent()) {
String bigDecimalMethod = BigDecimalArithmeticExprT.toBigDecimalMethod(operator);
BigDecimalArithmeticExprT convertedBigDecimalExpr = new BigDecimalArithmeticExprT(bigDecimalMethod, target, value);
return Optional.of(new AssignExprT(AssignExpr.Operator.ASSIGN, target, convertedBigDecimalExpr));
}
return Optional.empty();
}
use of org.drools.mvelcompiler.ast.AssignExprT in project drools by kiegroup.
the class LHSPhase method visit.
@Override
public TypedExpression visit(AssignExpr n, Void arg) {
logPhase("AssignExpr {}", n);
TypedExpression target = n.getTarget().accept(this, arg);
Optional<TypedExpression> bigDecimalConversion = withBigDecimalConversion(n, target, rhsOrError());
if (bigDecimalConversion.isPresent()) {
return bigDecimalConversion.get();
}
if (target instanceof FieldToAccessorTExpr || target instanceof VariableDeclaratorTExpr || target instanceof MapPutExprT) {
return target;
}
return new AssignExprT(n.getOperator(), target, rhsOrNull());
}
Aggregations