tkobayas commented on code in PR #6414:
URL:
https://github.com/apache/incubator-kie-drools/pull/6414#discussion_r2268550658
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/declaredtype/DescrTypeDefinition.java:
##########
@@ -243,15 +258,33 @@ private List<DescrFieldDefinition> processFields() {
private ProcessedTypeField processTypeField(int position, TypeFieldDescr
typeFieldDescr) {
DescrFieldDefinition typeField = new
DescrFieldDefinition(typeFieldDescr);
- List<DescrAnnotationDefinition> parsedAnnotations =
typeFieldDescr.getAnnotations().stream()
- .map(this::createAnnotationDefinition)
- .filter(Optional::isPresent)
- .map(Optional::get)
- .collect(toList());
+ // Create a map of successfully parsed annotations, keyed by original
annotation name
+ Map<String, DescrAnnotationDefinition> parsedAnnotations = new
HashMap<>();
+ for (AnnotationDescr ann : typeFieldDescr.getAnnotations()) {
+ Optional<DescrAnnotationDefinition> parsed =
createAnnotationDefinition(ann);
+ if (parsed.isPresent()) {
+ parsedAnnotations.put(ann.getName(), parsed.get());
+ }
+ }
- parsedAnnotations.stream().filter(a -> !a.isPosition()).forEach(a ->
processDefinitions(typeField, a));
+ parsedAnnotations.values().stream().filter(a ->
!a.isPosition()).forEach(a -> processDefinitions(typeField, a));
- int currentFieldPosition = setFieldPosition(position, typeField,
parsedAnnotations);
+ // Add built-in annotations and non-defined custom annotations as
field metadata
+ for (AnnotationDescr ann : typeFieldDescr.getAnnotations()) {
+ DescrAnnotationDefinition parsed =
parsedAnnotations.get(ann.getName());
+ if (parsed != null) {
+ // This annotation was successfully parsed - check if it's
built-in
+ if (isBuiltInAnnotation(parsed)) {
+ Object value = ann.getSingleValue();
+ typeField.addFieldMetaData(ann.getName(), value);
+ }
+ } else {
+ // This annotation failed to parse - it's a non-defined custom
annotation
+ typeField.addFieldMetaData(ann.getName(),
ann.getSingleValue());
Review Comment:
"unknown annotation properties" will end up with a build error, so this is
not a big issue. But I fix the code for clarification and readability.
--
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]