-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KIE-775] drools executable-model fails with a bind variable to a cal… #5636
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,7 +235,14 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) { | |
right = coerced.getCoercedRight(); | ||
|
||
final BinaryExpr combo = new BinaryExpr(left.getExpression(), right.getExpression(), operator); | ||
return of(new TypedExpression(combo, left.getType())); | ||
|
||
if (shouldConvertArithmeticBinaryToMethodCall(operator, left.getType(), right.getType())) { | ||
Expression expression = convertArithmeticBinaryToMethodCall(combo, of(typeCursor), ruleContext); | ||
java.lang.reflect.Type binaryType = getBinaryTypeAfterConversion(left.getType(), right.getType()); | ||
return of(new TypedExpression(expression, binaryType)); | ||
} else { | ||
return of(new TypedExpression(combo, left.getType())); | ||
} | ||
Comment on lines
+239
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR basically does "convert BigDecimal arithmetic BinaryExpr to MathodCallExpr" in ExpressionTyper. For handling BigInteger and adding BigInteger tests would be addressed by apache/incubator-kie-issues#753 |
||
} | ||
|
||
if (drlxExpr instanceof HalfBinaryExpr) { | ||
|
@@ -806,11 +813,12 @@ private TypedExpressionCursor binaryExpr(BinaryExpr binaryExpr) { | |
TypedExpression rightTypedExpression = right.getTypedExpression() | ||
.orElseThrow(() -> new NoSuchElementException("TypedExpressionResult doesn't contain TypedExpression!")); | ||
binaryExpr.setRight(rightTypedExpression.getExpression()); | ||
java.lang.reflect.Type binaryType = getBinaryType(leftTypedExpression, rightTypedExpression, binaryExpr.getOperator()); | ||
if (shouldConvertArithmeticBinaryToMethodCall(binaryExpr.getOperator(), binaryType)) { | ||
if (shouldConvertArithmeticBinaryToMethodCall(binaryExpr.getOperator(), leftTypedExpression.getType(), rightTypedExpression.getType())) { | ||
Expression compiledExpression = convertArithmeticBinaryToMethodCall(binaryExpr, leftTypedExpression.getOriginalPatternType(), ruleContext); | ||
java.lang.reflect.Type binaryType = getBinaryTypeAfterConversion(leftTypedExpression.getType(), rightTypedExpression.getType()); | ||
return new TypedExpressionCursor(compiledExpression, binaryType); | ||
} else { | ||
java.lang.reflect.Type binaryType = getBinaryType(leftTypedExpression, rightTypedExpression, binaryExpr.getOperator()); | ||
return new TypedExpressionCursor(binaryExpr, binaryType); | ||
} | ||
} | ||
|
@@ -819,7 +827,7 @@ private TypedExpressionCursor binaryExpr(BinaryExpr binaryExpr) { | |
* Converts arithmetic binary expression (including coercion) to method call using ConstraintCompiler. | ||
* This method can be generic, so we may centralize the calls in drools-model | ||
*/ | ||
private static Expression convertArithmeticBinaryToMethodCall(BinaryExpr binaryExpr, Optional<Class<?>> originalPatternType, RuleContext ruleContext) { | ||
public static Expression convertArithmeticBinaryToMethodCall(BinaryExpr binaryExpr, Optional<Class<?>> originalPatternType, RuleContext ruleContext) { | ||
ConstraintCompiler constraintCompiler = createConstraintCompiler(ruleContext, originalPatternType); | ||
CompiledExpressionResult compiledExpressionResult = constraintCompiler.compileExpression(printNode(binaryExpr)); | ||
return compiledExpressionResult.getExpression(); | ||
|
@@ -828,8 +836,15 @@ private static Expression convertArithmeticBinaryToMethodCall(BinaryExpr binaryE | |
/* | ||
* BigDecimal arithmetic operations should be converted to method calls. We may also apply this to BigInteger. | ||
*/ | ||
private static boolean shouldConvertArithmeticBinaryToMethodCall(BinaryExpr.Operator operator, java.lang.reflect.Type type) { | ||
return isArithmeticOperator(operator) && type.equals(BigDecimal.class); | ||
public static boolean shouldConvertArithmeticBinaryToMethodCall(BinaryExpr.Operator operator, java.lang.reflect.Type leftType, java.lang.reflect.Type rightType) { | ||
return isArithmeticOperator(operator) && (leftType.equals(BigDecimal.class) || rightType.equals(BigDecimal.class)); | ||
} | ||
|
||
/* | ||
* After arithmetic to method call conversion, BigDecimal should take precedence regardless of left or right. We may also apply this to BigInteger. | ||
*/ | ||
public static java.lang.reflect.Type getBinaryTypeAfterConversion(java.lang.reflect.Type leftType, java.lang.reflect.Type rightType) { | ||
return (leftType.equals(BigDecimal.class) || rightType.equals(BigDecimal.class)) ? BigDecimal.class : leftType; | ||
} | ||
|
||
private java.lang.reflect.Type getBinaryType(TypedExpression leftTypedExpression, TypedExpression rightTypedExpression, Operator operator) { | ||
|
@@ -936,6 +951,9 @@ private void promoteBigDecimalParameters(MethodCallExpr methodCallExpr, Class[] | |
Expression argumentExpression = methodCallExpr.getArgument(i); | ||
|
||
if (argumentType != actualArgumentType) { | ||
// unbind the original argumentExpression first, otherwise setArgument() will remove the argumentExpression from coercedExpression.childrenNodes | ||
// It will result in failing to find DrlNameExpr in AST at DrlsParseUtil.transformDrlNameExprToNameExpr() | ||
methodCallExpr.replace(argumentExpression, new NameExpr("placeholder")); | ||
Expression coercedExpression = new BigDecimalArgumentCoercion().coercedArgument(argumentType, actualArgumentType, argumentExpression); | ||
methodCallExpr.setArgument(i, coercedExpression); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this part may be duplicated withah, no, it's not duplicated. I think this is better because explicitly setting theAbstractExpressionBuilder.getBindingExpression()
boundExpr
.