Rikkola commented on code in PR #7160:
URL: https://github.com/apache/incubator-kie/pull/7160#discussion_r4193227876


##########
drools-model/drools-canonical-model/src/main/java/org/drools/model/impl/ViewPatternBuilder.java:
##########
@@ -194,6 +221,50 @@ public static Condition ruleItem2Condition(RuleItem 
ruleItem) {
         throw new UnsupportedOperationException( "Unknown " + ruleItem );
     }
 
+    /**
+     * Rewrites bare xor()/xnor() steps in a sequence by folding each such step
+     * with the immediately following positive step into an and(xor(...), 
next) pair.
+     * <p>
+     * {@code sequence(xor(a, b), c)} is legal sugar for {@code 
sequence(and(xor(a, b), c))}.
+     * The trailing-XOR check in the caller will catch {@code sequence(xor(a, 
b))} (no following step).
+     */
+    private static org.drools.model.SequenceStep[] 
rewriteXorSteps(org.drools.model.SequenceStep[] steps) {
+        boolean hasXor = false;
+        for (int i = 0; i < steps.length; i++) {
+            org.drools.model.SequenceStep step = steps[i];
+            if (step instanceof CombinedExprViewItem) {
+                Condition.Type t = ((CombinedExprViewItem) step).getType();
+                if ((t == Condition.Type.XOR || t == Condition.Type.XNOR) && i 
+ 1 < steps.length) {
+                    hasXor = true;
+                    break;
+                }
+            }
+        }
+        if (!hasXor) {
+            return steps;
+        }
+        List<org.drools.model.SequenceStep> result = new ArrayList<>();
+        for (int i = 0; i < steps.length; i++) {
+            org.drools.model.SequenceStep step = steps[i];
+            if (step instanceof CombinedExprViewItem) {
+                Condition.Type t = ((CombinedExprViewItem) step).getType();
+                if ((t == Condition.Type.XOR || t == Condition.Type.XNOR) && i 
+ 1 < steps.length) {
+                    // Wrap: and(xor/xnor(...), nextStep)
+                    CombinedExprViewItem wrapped = new CombinedExprViewItem(
+                            Condition.Type.AND,
+                            new ViewItem[]{(ViewItem) step, (ViewItem) steps[i 
+ 1]});
+                    result.add(wrapped);
+                    i++; // consume the following step

Review Comment:
   Fixed



-- 
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