olabusayoT commented on code in PR #1366:
URL: https://github.com/apache/daffodil/pull/1366#discussion_r1854455430


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

Review Comment:
   So the idea behind this was if we have something like the below. Assuming 
element a uses all 4 properties, we only want to propagate prop3 and prop4 to 
t1, since prop1 and prop2 aren't carried by the simpletype, but by the element 
itself.
   I'll reword the comment not to use shared, since that is unclear in this 
context. But we don't need to remove any uncarried properties, since prop1 and 
prop2 are never added in the first place.
   
   ```xml
       <element name="a" dfdl:prop1="" dfdl:prop2="" type="t1"/>
       <simpleType name="t1">
           <annotation>
             <appinfo>
               <dfdl:simpleType prop3="" prop4=""/>
             </appinfo>
           </annotation>
       </simpleType>
   ```
   
   



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

Reply via email to