olabusayoT commented on code in PR #1366:
URL: https://github.com/apache/daffodil/pull/1366#discussion_r1859104353
##########
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
+ // we don't need the check for what it carries since all properties
on the type are shared
+ // by the element using it
+ std.propCache.foreach(kv => ele.propCache.put(kv._1, kv._2))
+ // copy the used properties from the element to the type
+ ele.propCache.foreach(kv =>
+ if (std.formatAnnotation.justThisOneProperties.contains(kv._1)) {
+ // only add the used properties that the simple type carries,
not any local element properties that aren't shared
+ std.propCache.put(kv._1, kv._2)
+ }
+ )
+ // propagate through the element's simple type base chain
+ std.propagateUsedProperties
Review Comment:
> Root.refMap to find the other simple type defs which reference this one
Root.refMap doesn't track derived types to their base types, attempts to add
it broke things and this comment in Nesting makes it clear it's not supposed to
do that
```scala
// The other kinds of references (to escape schemes, to named formats, or
// from derived types to their base types) shouldn't be encountered here.
```
--
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]