This is an automated email from the ASF dual-hosted git repository.

jadams pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new 37f7e66e7 Warn when DFDL annotations placed on group definition
37f7e66e7 is described below

commit 37f7e66e7ab790e0f1370c43ae81e35e6f21786e
Author: Josh Adams <[email protected]>
AuthorDate: Fri Dec 23 09:50:16 2022 -0500

    Warn when DFDL annotations placed on group definition
    
    DFDL Annotations placed on group definitions will be ignored,
    so we should warn users that this is occurring.
    
    DAFFODIL-2668
---
 .../core/dsom/AnnotatedSchemaComponent.scala       | 11 +++--
 .../org/apache/daffodil/core/dsom/GroupDef.scala   | 14 +++++++
 .../daffodil/section07/variables/variables.tdml    | 47 ++++++++++++++++++++++
 .../section07/variables/TestVariables.scala        |  2 +
 4 files changed, 71 insertions(+), 3 deletions(-)

diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/AnnotatedSchemaComponent.scala
 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/AnnotatedSchemaComponent.scala
index 7d5b60c5a..ac47a4af0 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/AnnotatedSchemaComponent.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/AnnotatedSchemaComponent.scala
@@ -19,6 +19,7 @@ package org.apache.daffodil.core.dsom
 
 import scala.collection.mutable
 import scala.xml.Node
+import scala.xml.NodeSeq
 
 import org.apache.daffodil.lib.api.WarnID
 import org.apache.daffodil.lib.equality._
@@ -412,9 +413,8 @@ trait AnnotatedMixin { self: AnnotatedSchemaComponent =>
 
   private def isDfdlNamespace(ns: String): Boolean = ns.contains("ogf") && 
ns.contains("dfdl")
 
-  lazy val dfdlAppInfos = {
-    val ais = (annotationNode \ "appinfo")
-    val dais = ais.filter { ai =>
+  def getDFDLAppinfos(appinfos: NodeSeq): NodeSeq = {
+    val dais = appinfos.filter { ai =>
       {
         ai.attribute("source") match {
           case None => {
@@ -461,6 +461,11 @@ trait AnnotatedMixin { self: AnnotatedSchemaComponent =>
     dais
   }
 
+  lazy val dfdlAppInfos = {
+    val ais = (annotationNode \ "appinfo")
+    getDFDLAppinfos(ais)
+  }
+
   /**
    * The DFDL annotations on the component, as objects
    * that are subtypes of DFDLAnnotation.
diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/GroupDef.scala 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/GroupDef.scala
index 2f3618de2..59ffbbe20 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/GroupDef.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/GroupDef.scala
@@ -21,6 +21,7 @@ import scala.xml.Comment
 import scala.xml.Node
 import scala.xml.Text
 
+import org.apache.daffodil.lib.api.WarnID
 import org.apache.daffodil.lib.exceptions.Assert
 
 object GlobalGroupDef {
@@ -118,6 +119,7 @@ sealed abstract class GlobalGroupDef(
 
   def groupMembers = {
     validateChoiceBranchKey()
+    checkForGroupDefAnnotations()
     this.groupMembersNotShared
   }
 
@@ -131,6 +133,18 @@ sealed abstract class GlobalGroupDef(
     }
   }
 
+  private def checkForGroupDefAnnotations(): Unit = {
+    // Ensure that the group definition itself does not have any annotations.
+    // Annotations should only be on group references or children of the group
+    // definition
+    val dais = getDFDLAppinfos(defXML \ "annotation" \ "appinfo")
+    if (dais.nonEmpty)
+      SDW(
+        WarnID.InvalidAnnotationPoint,
+        "Annotations placed directly on a group definition will be ignored by 
DFDL. Any annotation expected to be processed by DFDL should instead be placed 
on the group reference, sequence or choice."
+      )
+  }
+
   final override lazy val name = defXML
     .attribute("name")
     .map { _.text }
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section07/variables/variables.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section07/variables/variables.tdml
index 5d8d167df..cbdfcde97 100644
--- 
a/daffodil-test/src/test/resources/org/apache/daffodil/section07/variables/variables.tdml
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section07/variables/variables.tdml
@@ -2708,4 +2708,51 @@
     </tdml:infoset>
   </tdml:parserTestCase>
 
+  <tdml:defineSchema name="nviInGroupDecl">
+
+    <xs:include 
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+    <dfdl:defineVariable defaultValue="x" name="var1" type="xs:string"/>
+
+    <dfdl:format ref="GeneralFormat" />
+
+    <xs:group name="g1">
+      <xs:annotation>
+        <xs:appinfo source="http://www.ogf.org/dfdl/";>
+          <dfdl:newVariableInstance ref="ex:var1" defaultValue="test"/>
+        </xs:appinfo>
+      </xs:annotation>
+      <xs:sequence>
+        <xs:element name="e1" type="xs:string" dfdl:inputValueCalc="{ $ex:var1 
}"/>
+      </xs:sequence>
+    </xs:group>
+
+    <xs:element name="root">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:group ref="ex:g1"/>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+
+  </tdml:defineSchema>
+
+  <tdml:parserTestCase name="nviInGroupDecl_01" root="root" 
model="nviInGroupDecl">
+    <tdml:document></tdml:document>
+    <tdml:warnings>
+      <tdml:warning>Schema Definition Warning</tdml:warning>
+      <tdml:warning>Annotations</tdml:warning>
+      <tdml:warning>group definition</tdml:warning>
+      <tdml:warning>ignored</tdml:warning>
+    </tdml:warnings>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <root>
+          <e1>x</e1>
+        </root>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+
 </tdml:testSuite>
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/section07/variables/TestVariables.scala
 
b/daffodil-test/src/test/scala/org/apache/daffodil/section07/variables/TestVariables.scala
index 061cc9d54..3c8851b80 100644
--- 
a/daffodil-test/src/test/scala/org/apache/daffodil/section07/variables/TestVariables.scala
+++ 
b/daffodil-test/src/test/scala/org/apache/daffodil/section07/variables/TestVariables.scala
@@ -163,6 +163,8 @@ class TestVariables {
     runner.runOneTest("multipleVarReadInPoU_01")
   }
 
+  @Test def test_nviInGroupDecl_01(): Unit = { 
runner.runOneTest("nviInGroupDecl_01") }
+
   /*****************************************************************/
   val tdmlVal = XMLUtils.TDML_NAMESPACE
   val dfdl = XMLUtils.DFDL_NAMESPACE

Reply via email to