alishaaaqil commented on code in PR #7230:
URL: https://github.com/apache/incubator-kie/pull/7230#discussion_r4358100269


##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNEvaluatorCompiler.java:
##########
@@ -394,6 +399,51 @@ private DMNExpressionEvaluator 
compileContext(DMNCompilerContext ctx, DMNModelIm
         return ctxEval;
     }
 
+    /**
+     * Checks if the given <code>Context</code> produces the result of the 
<code>Decision</code> or <code>BusinessKnowledgeModel</code>:
+     * it is the root expression of the node, or a 
<code>then</code>/<code>else</code> branch of a root <code>Conditional</code>.
+     * The model elements are compared, since the parent links are populated 
only when a model is unmarshalled.
+     * @param ctxDef the context being compiled
+     * @param node the node the context belongs to
+     * @return <code>true</code> if the value of the context is the result of 
the node
+     */
+    private static boolean isResultOfDecisionOrBKM(Context ctxDef, DMNBaseNode 
node) {
+        return isSameOrConditionalBranchOf(getRootExpression(node), ctxDef);
+    }
+
+    /**
+     * @return the expression of the Decision, or the body of the function 
definition of the BKM; <code>null</code> if not available
+     */
+    private static Expression getRootExpression(DMNBaseNode node) {
+        NamedElement source = node.getSource();
+        if (source instanceof Decision decision) {
+            return decision.getExpression();
+        }
+        if (source instanceof BusinessKnowledgeModel bkm) {
+            FunctionDefinition encapsulatedLogic = bkm.getEncapsulatedLogic();
+            return encapsulatedLogic != null ? 
encapsulatedLogic.getExpression() : null;
+        }
+        return null;
+    }
+
+    private static boolean isSameOrConditionalBranchOf(Expression root, 
Expression expression) {
+        if (root == null) {
+            return false;
+        }
+        if (root == expression) {

Review Comment:
   Yes,  it's a reference comparison, on purpose. We need to know whether the 
context is the very body of the Decision/BKM (or one of its conditional 
branches), not just an equal one. The null check is gone (the root now comes 
back as an Optional), and isSameOrConditionalBranchOfAnotherInstance covers it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to