tkobayas commented on code in PR #6024:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6024#discussion_r1678771930


##########
drools-base/src/main/java/org/drools/base/rule/EvalCondition.java:
##########
@@ -223,4 +230,36 @@ public void setCloned(List<EvalCondition> cloned) {
     public String toString() {
         return this.expression.toString();
     }
+
+    public static void logWarnIfImproperEval(EvalCondition evalCondition, 
String evalExpression) {
+        if (warnLogCounter == 10) {
+            warnLogCounter++;
+            LOG.warn("More eval warnings will be suppressed...");
+            return;
+        } else if (warnLogCounter > 10) {
+            return; // avoid flooding the logs
+        }
+
+        if (evalExpression == null || evalExpression.isEmpty()) {
+            return; // cannot provide a meaningful warning
+        }
+
+        StringBuilder sb = new StringBuilder();
+        for (Declaration declaration : 
evalCondition.getRequiredDeclarations()) {
+            if (declaration.getPattern() != null) {
+                sb.append("'");
+                sb.append(declaration.getIdentifier());
+                sb.append("' comes from previous pattern '");
+                String className = 
declaration.getPattern().getObjectType().getClassName();
+                sb.append(className.substring(className.lastIndexOf('.') + 1));
+                sb.append("'. ");
+            }
+        }

Review Comment:
   The criteria of the warning is "If the eval uses a declaration which comes 
from previous pattern". I guess, most of eval usages meet the case. Do you 
think of other criteria? @mariofusco 



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