olabusayoT commented on code in PR #1366:
URL: https://github.com/apache/daffodil/pull/1366#discussion_r1854410603
##########
daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/AnnotatedSchemaComponent.scala:
##########
@@ -377,6 +378,118 @@ trait AnnotatedSchemaComponent
val res = schemaDocument.formatAnnotation.formatChain
res
}
+
+ /**
+ * Used to propagate used properties through all element/group references,
element declarations
+ * and simple types. This is necessary because we have elements being
referenced
+ * by multiple element ref, where the first element gets its propCache
populated with
+ * the properties its used, and the second element doesn't because of
sharing. With
+ * this val, we copy used properties from element refs to elements, group
refs to groups,
+ * from elements to their simple types, if the simple type is annotated with
the property,
+ * and from simple types to their base types
+ */
+ final lazy val propagateUsedProperties: Unit = {
+ this match {
+ case ref: GroupRef =>
+ val groupBeingReferenced = ref.groupDef
+ // if the groupBeingReferenced carries the property then add the
property to its propCache
+ ref.propCache.foreach { kv =>
+ if
(groupBeingReferenced.formatAnnotation.justThisOneProperties.contains(kv._1)) {
+ groupBeingReferenced.propCache.put(kv._1, kv._2)
+ }
+ }
+ case ref: AbstractElementRef =>
+ val elementBeingReferenced = ref.optReferredToComponent.get
+ ref.propCache.foreach(kv =>
+ // if the elementBeingReferenced or its simpleType carries the
property
+ // then add the property to its propCache
+ if (
+
elementBeingReferenced.formatAnnotation.justThisOneProperties.contains(kv._1)
+ || elementBeingReferenced.optSimpleType.exists {
+ case std: SimpleTypeDefBase =>
+ std.formatAnnotation.justThisOneProperties.contains(kv._1)
+ case _ => false
+ }
+ ) {
+ // only add the used properties that the elementBeingReferenced or
its simple type carries,
+ // not any local properties that aren't shared
+ elementBeingReferenced.propCache.put(kv._1, kv._2)
+ // propagate used properties from element to its simpletype and
vice versa
+ elementBeingReferenced.propagateUsedProperties
+ }
+ )
+ case ele: ElementDeclMixin =>
+ val ost = ele.optSimpleType
+ ost.collect { case std: SimpleTypeDefBase =>
+ // if the type has used properties transfer it to the element that's
using it
Review Comment:
I was thinking if the type is used by 2 different elements, and the first
propgagates its used properties to the simpleType, then the 2nd element would
want to inherit those used properties as well
--
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]