Copilot commented on code in PR #6738:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6738#discussion_r3479537839


##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/declaredtype/EnumGenerator.java:
##########
@@ -104,8 +107,19 @@ private void createGetter(Type type, String key) {
     private void addEnumerationValue(EnumLiteralDescr enumLiteral) {
         EnumConstantDeclaration element = new 
EnumConstantDeclaration(enumLiteral.getName());
         for (String constructorArgument : enumLiteral.getConstructorArgs()) {
-            element.addArgument(new NameExpr(constructorArgument));
+            element.addArgument(parseConstructorArgument(constructorArgument));
         }
         enumDeclaration.addEntry(element);
     }
+
+    /**
+     * Parses an enum-constant constructor argument as a Java expression.
+     */
+    private Expression parseConstructorArgument(String constructorArgument) {
+        try {
+            return StaticJavaParser.parseExpression(constructorArgument);
+        } catch (ParseProblemException e) {
+            return new NameExpr(constructorArgument);
+        }
+    }

Review Comment:
   Catching ParseProblemException and falling back to `new 
NameExpr(constructorArgument)` hides invalid Java expressions and tends to 
produce later, harder-to-diagnose compilation errors. Other codegen paths 
(e.g., MaterializedLambda) fail fast on invalid JavaParser expressions; doing 
the same here would give clearer, earlier diagnostics for invalid enum 
constructor arguments.



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