Copilot commented on code in PR #7270:
URL: https://github.com/apache/incubator-kie/pull/7270#discussion_r4490216565


##########
drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/util/TypeDeclarationUtil.java:
##########
@@ -54,6 +55,34 @@ public class TypeDeclarationUtil {
         "propertyChangeSupport"
     );
 
+    private static final Map<String, String> KNOWN_ANNOTATIONS_BY_FQN = Map.of(
+        "org.kie.api.definition.type.Role", "role",
+        "org.kie.api.definition.type.Duration", "duration",
+        "org.kie.api.definition.type.Timestamp", "timestamp",
+        "org.kie.api.definition.type.Expires", "expires",
+        "org.kie.api.definition.type.PropertyReactive", "propertyReactive",
+        "org.kie.api.definition.type.ClassReactive", "classReactive",
+        "org.kie.api.definition.type.PropertyChangeSupport", 
"propertyChangeSupport"
+    );
+
+    private static final Map<String, String> KNOWN_ANNOTATIONS_BY_LOWER_NAME = 
KNOWN_ANNOTATIONS.stream()
+            .collect(Collectors.toMap(name -> name.toLowerCase(Locale.ROOT), 
name -> name));
+
+    /**
+     * Canonical name of a built-in type annotation as written in a declare 
block: the DRL
+     * parser also accepts the Java (capitalized) form of these annotations, 
e.g. {@code @Role}
+     * and {@code @Expires}, and the classic compiler resolves both spellings 
— so an unqualified
+     * name matches its built-in case-insensitively and maps to the canonical 
spelling. A
+     * qualified name only maps when it is a built-in's own FQN; any other 
qualified annotation
+     * stays itself (custom metadata).
+     */
+    private static String canonicalAnnotationName(String name) {
+        if (name.indexOf('.') >= 0) {
+            return KNOWN_ANNOTATIONS_BY_FQN.getOrDefault(name, name);
+        }
+        return 
KNOWN_ANNOTATIONS_BY_LOWER_NAME.getOrDefault(name.toLowerCase(Locale.ROOT), 
name);

Review Comment:
   An imported custom annotation such as `com.acme.ClassReactive`, used as 
`@ClassReactive` on a redeclared Java class, now disables property reactivity 
and loses its custom metadata. `AnnotationNormalizer` resolves its identity, 
but `POJOGenerator.processTypeMetadata()` emits only the simple name, so the 
qualified-name guard cannot protect it. Use the resolved annotation identity to 
classify built-ins while retaining the original custom metadata key, and add a 
regression test for an imported annotation with a colliding name.



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