olabusayoT commented on code in PR #1366:
URL: https://github.com/apache/daffodil/pull/1366#discussion_r1858825805
##########
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:
> structure of just the properties that are used so as to isolate from those
that are unused
Propcache only contains used properties. We don't add in any unused
properties
> olds only properties in the referencer's propCache that are NOT found in
the referenced object's propCache, so that this new structure is not redundant
with the contents of the propCache.
Doesn't that mean checkUnunsedProperties would have to check propCache as
well as this new structure?
--
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]