This is an automated email from the ASF dual-hosted git repository.
olabusayo 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 34630b58a Assign Type to Overridden UDF Function
34630b58a is described below
commit 34630b58a10ce640b6ed4d1185acf15a1473585d
Author: olabusayoT <[email protected]>
AuthorDate: Fri Mar 14 13:27:00 2025 -0400
Assign Type to Overridden UDF Function
- specify types for overridden getUserDefinedFunctionClasses method
- remove empty namespace from xml literals
- specify longs for digits otherwise the assert fails on comparing an int
and a long
- During NonEmptyString initialization, it requires TypeNode(String), which
requires NodeInfo to be initialized, which tries to initialize the members of
allTypes of which NonEmptyString is one. This results in NonEmptyString
returning null. So we update the code to not force initialization of allType
members during NodeInfo initialization. Instead, the members are initialized on
an as needed basis
- Also we make parents call by name so they can also reference their
children
- update scalafmt to format import selectors one per line as per example
below. We already do this in code, but this is just to ensure newer code
matches the format
```
import a.b.{
c,
d
}
```
DAFFODIL-2975
---
.scalafmt.conf | 1 +
.../io/TestInputSourceDataInputStream.scala | 4 +-
.../apache/daffodil/runtime1/dpath/NodeInfo.scala | 95 ++++++++--------------
.../daffodil/runtime1/layers/TestCheckDigit.scala | 8 +-
.../StringFunctions/StringFunctionsProvider.scala | 2 +-
.../StringFunctions/StringFunctionsProvider.scala | 2 +-
.../StringFunctions/StringFunctionsProvider.scala | 2 +-
.../StringFunctions/StringFunctionsProvider.scala | 2 +-
.../StringFunctions/StringFunctionsProvider.scala | 2 +-
.../StringFunctions/StringFunctionsProvider.scala | 2 +-
.../IntegerFunctionsProvider.scala | 2 +-
.../StringFunctions/StringFunctionsProvider.scala | 2 +-
.../SupportedTypesFunctionsProvider.scala | 2 +-
13 files changed, 49 insertions(+), 77 deletions(-)
diff --git a/.scalafmt.conf b/.scalafmt.conf
index eab66706f..336b06241 100644
--- a/.scalafmt.conf
+++ b/.scalafmt.conf
@@ -20,6 +20,7 @@ docstrings.style = keep
indent.defnSite = 2
indent.extendSite = 2
maxColumn = 96
+importSelectors = noBinPack
rewrite.imports.groups = [
["scala\\..*", "java\\..*", "javax\\..*"],
["org\\.apache\\.daffodil\\..*"],
diff --git
a/daffodil-io/src/test/scala/org/apache/daffodil/io/TestInputSourceDataInputStream.scala
b/daffodil-io/src/test/scala/org/apache/daffodil/io/TestInputSourceDataInputStream.scala
index 6792b9978..9a4f2ca29 100644
---
a/daffodil-io/src/test/scala/org/apache/daffodil/io/TestInputSourceDataInputStream.scala
+++
b/daffodil-io/src/test/scala/org/apache/daffodil/io/TestInputSourceDataInputStream.scala
@@ -332,7 +332,7 @@ class TestInputSourceDataInputStream {
@Test def testUnsignedBigInt1(): Unit = {
val dis = InputSourceDataInputStream(List(0xff).map { _.toByte }.toArray)
val ml = dis.getUnsignedBigInt(2, finfo)
- assertEqualsTyped(2, dis.bitPos0b)
+ assertEqualsTyped(2L, dis.bitPos0b)
val expected = JBigInt.valueOf(3)
assertEqualsTyped[JBigInt](expected, ml)
}
@@ -342,7 +342,7 @@ class TestInputSourceDataInputStream {
_.toByte
}.toArray)
val ml = dis.getUnsignedBigInt(40, finfo)
- assertEqualsTyped(40, dis.bitPos0b)
+ assertEqualsTyped(40L, dis.bitPos0b)
val expected = JBigInt.valueOf(0xc1c2c3c4c5L)
assertEqualsTyped[JBigInt](expected, ml)
}
diff --git
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala
index bbc58fffd..19acedf22 100644
---
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala
+++
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala
@@ -34,7 +34,6 @@ import java.net.URISyntaxException
import org.apache.daffodil.lib.calendar.DFDLDateConversion
import org.apache.daffodil.lib.calendar.DFDLDateTimeConversion
import org.apache.daffodil.lib.calendar.DFDLTimeConversion
-import org.apache.daffodil.lib.exceptions.Assert
import org.apache.daffodil.lib.util.Delay
import org.apache.daffodil.lib.util.Enum
import org.apache.daffodil.lib.util.MaybeInt
@@ -84,33 +83,15 @@ sealed abstract class TypeNode private (
childrenDelay: Delay[Seq[NodeInfo.Kind]]
) extends Serializable
with NodeInfo.Kind {
-
def this(parents: => Seq[NodeInfo.Kind], children: => Seq[NodeInfo.Kind]) =
this(Delay("TypeNode", parents), Delay("TypeNode", children))
- def this(parentArg: NodeInfo.Kind, childrenArg: => Seq[NodeInfo.Kind]) =
- this(Delay("TypeNode", Seq(parentArg)), Delay("TypeNode", childrenArg))
-
def this(parentArg: => NodeInfo.Kind) =
this(
Delay("TypeNode", Seq(parentArg)),
Delay("TypeNode", Seq[NodeInfo.Kind](NodeInfo.Nothing))
)
- /**
- * Cyclic structures require an initialization
- */
- lazy val initialize: Unit = {
- parents
- children // demand their value
- parents.foreach { p =>
- // if this fails, it is because cyclic graph construction of the types
- // has failed. For some reason, this doesn't cause a stack overflow, but
- // you just get null as the value of one of the case object type nodes.
- Assert.invariant(p ne null)
- }
- }
-
final override lazy val parents = parentsDelay.value
final override lazy val children = childrenDelay.value
}
@@ -122,12 +103,11 @@ sealed abstract class TypeNode private (
*/
sealed abstract class PrimTypeNode(
val dfdlType: DFDLPrimType,
- parent: NodeInfo.Kind,
+ parent: => NodeInfo.Kind,
childrenArg: => Seq[NodeInfo.Kind]
-) extends TypeNode(parent, childrenArg)
+) extends TypeNode(Seq(parent), childrenArg)
with NodeInfo.PrimType {
-
- def this(javaType: DFDLPrimType, parent: NodeInfo.Kind) =
+ def this(javaType: DFDLPrimType, parent: => NodeInfo.Kind) =
this(javaType, parent, Seq(NodeInfo.Nothing))
}
@@ -173,16 +153,6 @@ class InvalidPrimitiveDataException(msg: String, cause:
Throwable = null)
*/
object NodeInfo extends Enum {
- /**
- * Cyclic structures require initialization
- */
- private lazy val initialize: Boolean = {
- allTypes.foreach {
- _.initialize
- }
- true
- }
-
// Primitives are not "global" because they don't appear in any schema
document
sealed trait PrimType extends PrimTypeKind {
@@ -256,6 +226,7 @@ object NodeInfo extends Enum {
case _ => QName.createGlobal(name, NoNamespace, scala.xml.TopScope)
}
}
+
val ClassString = classOf[java.lang.String]
val ClassIntBoxed = classOf[java.lang.Integer]
val ClassIntPrim = classOf[scala.Int]
@@ -392,14 +363,16 @@ object NodeInfo extends Enum {
protected sealed trait AnySimpleTypeKind extends AnyType.Kind {
final def primType: PrimType = optPrimType.get
}
- case object AnySimpleType extends TypeNode(AnyType, Seq(AnyAtomic)) with
AnySimpleTypeKind {
+ case object AnySimpleType
+ extends TypeNode(Seq(AnyType), Seq(AnyAtomic))
+ with AnySimpleTypeKind {
type Kind = AnySimpleTypeKind
}
protected sealed trait AnyAtomicKind extends AnySimpleType.Kind
case object AnyAtomic
extends TypeNode(
- AnySimpleType,
+ Seq(AnySimpleType),
Seq(String, Numeric, Boolean, Opaque, AnyDateTime, AnyURI)
)
with AnyAtomicKind {
@@ -408,27 +381,27 @@ object NodeInfo extends Enum {
protected sealed trait NumericKind extends AnyAtomic.Kind
case object Numeric
- extends TypeNode(AnyAtomic, Seq(SignedNumeric, UnsignedNumeric))
+ extends TypeNode(Seq(AnyAtomic), Seq(SignedNumeric, UnsignedNumeric))
with NumericKind {
type Kind = NumericKind
}
protected sealed trait SignedNumericKind extends Numeric.Kind
case object SignedNumeric
- extends TypeNode(Numeric, Seq(Float, Double, Decimal))
+ extends TypeNode(Seq(Numeric), Seq(Float, Double, Decimal))
with SignedNumericKind {
type Kind = SignedNumericKind
}
protected sealed trait UnsignedNumericKind extends Numeric.Kind
case object UnsignedNumeric
- extends TypeNode(Numeric, Seq(NonNegativeInteger))
+ extends TypeNode(Seq(Numeric), Seq(NonNegativeInteger))
with UnsignedNumericKind {
type Kind = UnsignedNumericKind
}
protected sealed trait OpaqueKind extends AnyAtomic.Kind
- case object Opaque extends TypeNode(AnyAtomic, Seq(HexBinary)) with
OpaqueKind {
+ case object Opaque extends TypeNode(Seq(AnyAtomic), Seq(HexBinary)) with
OpaqueKind {
type Kind = OpaqueKind
}
@@ -452,33 +425,33 @@ object NodeInfo extends Enum {
protected sealed trait AnyDateTimeKind extends AnyAtomicKind
case object AnyDateTime
- extends TypeNode(AnyAtomic, Seq(Date, Time, DateTime))
+ extends TypeNode(Seq(AnyAtomic), Seq(Date, Time, DateTime))
with AnyDateTimeKind {
type Kind = AnyDateTimeKind
}
// One might think these can be def, but scala insists on "stable identifier"
// where these are used in case matching.
- val String = PrimType.String
- val Int = PrimType.Int
- val Byte = PrimType.Byte
- val Short = PrimType.Short
- val Long = PrimType.Long
- val Integer = PrimType.Integer
- val Decimal = PrimType.Decimal
- val UnsignedInt = PrimType.UnsignedInt
- val UnsignedByte = PrimType.UnsignedByte
- val UnsignedShort = PrimType.UnsignedShort
- val UnsignedLong = PrimType.UnsignedLong
- val NonNegativeInteger = PrimType.NonNegativeInteger
- val Double = PrimType.Double
- val Float = PrimType.Float
- val HexBinary = PrimType.HexBinary
- val AnyURI = PrimType.AnyURI
- val Boolean = PrimType.Boolean
- val DateTime = PrimType.DateTime
- val Date = PrimType.Date
- val Time = PrimType.Time
+ lazy val String = PrimType.String
+ lazy val Int = PrimType.Int
+ lazy val Byte = PrimType.Byte
+ lazy val Short = PrimType.Short
+ lazy val Long = PrimType.Long
+ lazy val Integer = PrimType.Integer
+ lazy val Decimal = PrimType.Decimal
+ lazy val UnsignedInt = PrimType.UnsignedInt
+ lazy val UnsignedByte = PrimType.UnsignedByte
+ lazy val UnsignedShort = PrimType.UnsignedShort
+ lazy val UnsignedLong = PrimType.UnsignedLong
+ lazy val NonNegativeInteger = PrimType.NonNegativeInteger
+ lazy val Double = PrimType.Double
+ lazy val Float = PrimType.Float
+ lazy val HexBinary = PrimType.HexBinary
+ lazy val AnyURI = PrimType.AnyURI
+ lazy val Boolean = PrimType.Boolean
+ lazy val DateTime = PrimType.DateTime
+ lazy val Date = PrimType.Date
+ lazy val Time = PrimType.Time
protected sealed trait PrimTypeKind extends AnyAtomic.Kind
@@ -1048,6 +1021,4 @@ object NodeInfo extends Enum {
NonEmptyString,
Nothing
) ++ allAbstractTypes
-
- initialize // initialize self - creates all cyclic structures
}
diff --git
a/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestCheckDigit.scala
b/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestCheckDigit.scala
index bb1236dfd..633c56aaf 100644
---
a/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestCheckDigit.scala
+++
b/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestCheckDigit.scala
@@ -114,7 +114,7 @@ class TestCheckDigit extends TdmlTests {
}
val okInfoset: Elem =
- <ex:e1 xmlns="" xmlns:ex={example}>
+ <ex:e1 xmlns:ex={example}>
<value>2021-09-25</value>
<checkDigit>1</checkDigit>
<computedCheckDigit>1</computedCheckDigit>
@@ -200,7 +200,7 @@ class TestCheckDigit extends TdmlTests {
val sch = cdSchema(10, "ascii")
val data = "123:6"
val infoset =
- <ex:e1 xmlns="" xmlns:ex={example}>
+ <ex:e1 xmlns:ex={example}>
<value>123</value>
<checkDigit>0</checkDigit>
<computedCheckDigit>0</computedCheckDigit>
@@ -212,7 +212,7 @@ class TestCheckDigit extends TdmlTests {
val sch = cdSchema(5, "ascii")
val data = "1234567890:1"
val infoset =
- <ex:e1 xmlns="" xmlns:ex={example}>
+ <ex:e1 xmlns:ex={example}>
<value>1234567890</value>
<checkDigit>0</checkDigit>
<computedCheckDigit>0</computedCheckDigit>
@@ -228,7 +228,7 @@ class TestCheckDigit extends TdmlTests {
val sch = cdSchema(10, "notACharsetName")
val data = "1234567890:1"
val infoset =
- <ex:e1 xmlns="" xmlns:ex={example}>
+ <ex:e1 xmlns:ex={example}>
<value>1234567890</value>
<checkDigit>0</checkDigit>
<computedCheckDigit>0</computedCheckDigit>
diff --git
a/daffodil-udf/src/test/scala/org/sbadudfs/functionclasses/StringFunctions/StringFunctionsProvider.scala
b/daffodil-udf/src/test/scala/org/sbadudfs/functionclasses/StringFunctions/StringFunctionsProvider.scala
index 1f4a2e188..78c794a19 100644
---
a/daffodil-udf/src/test/scala/org/sbadudfs/functionclasses/StringFunctions/StringFunctionsProvider.scala
+++
b/daffodil-udf/src/test/scala/org/sbadudfs/functionclasses/StringFunctions/StringFunctionsProvider.scala
@@ -26,7 +26,7 @@ import org.apache.daffodil.udf.UserDefinedFunctionProvider
* Contains incorrect implementation of lookup function
*/
class StringFunctionsProvider extends UserDefinedFunctionProvider {
- override def getUserDefinedFunctionClasses = {
+ override def getUserDefinedFunctionClasses: Array[Class[?]] = {
Array(classOf[ReverseWords], classOf[Reverse])
}
diff --git
a/daffodil-udf/src/test/scala/org/sbadudfs/functionclasses2/StringFunctions/StringFunctionsProvider.scala
b/daffodil-udf/src/test/scala/org/sbadudfs/functionclasses2/StringFunctions/StringFunctionsProvider.scala
index 7aaf3924b..d94cb3fd0 100644
---
a/daffodil-udf/src/test/scala/org/sbadudfs/functionclasses2/StringFunctions/StringFunctionsProvider.scala
+++
b/daffodil-udf/src/test/scala/org/sbadudfs/functionclasses2/StringFunctions/StringFunctionsProvider.scala
@@ -31,7 +31,7 @@ class StringFunctionsProvider extends
UserDefinedFunctionProvider {
val nonSerializable = new SomeNonSerializableClass
val serializable = new SomeSerializableClass
- override def getUserDefinedFunctionClasses = {
+ override def getUserDefinedFunctionClasses: Array[Class[?]] = {
Array(classOf[GetNonSerializableState], classOf[GetSerializableState])
}
diff --git
a/daffodil-udf/src/test/scala/org/sbadudfs/udfexceptions/evaluating/StringFunctions/StringFunctionsProvider.scala
b/daffodil-udf/src/test/scala/org/sbadudfs/udfexceptions/evaluating/StringFunctions/StringFunctionsProvider.scala
index 837bea718..9eb7caf30 100644
---
a/daffodil-udf/src/test/scala/org/sbadudfs/udfexceptions/evaluating/StringFunctions/StringFunctionsProvider.scala
+++
b/daffodil-udf/src/test/scala/org/sbadudfs/udfexceptions/evaluating/StringFunctions/StringFunctionsProvider.scala
@@ -28,7 +28,7 @@ import
org.apache.daffodil.udf.exceptions.UserDefinedFunctionProcessingError
*/
class StringFunctionsProvider extends UserDefinedFunctionProvider {
- override def getUserDefinedFunctionClasses = {
+ override def getUserDefinedFunctionClasses: Array[Class[?]] = {
Array(classOf[ReverseWords], classOf[Reverse])
}
}
diff --git
a/daffodil-udf/src/test/scala/org/sbadudfs/udfexceptions2/StringFunctions/StringFunctionsProvider.scala
b/daffodil-udf/src/test/scala/org/sbadudfs/udfexceptions2/StringFunctions/StringFunctionsProvider.scala
index bf69007ff..62dfe4717 100644
---
a/daffodil-udf/src/test/scala/org/sbadudfs/udfexceptions2/StringFunctions/StringFunctionsProvider.scala
+++
b/daffodil-udf/src/test/scala/org/sbadudfs/udfexceptions2/StringFunctions/StringFunctionsProvider.scala
@@ -27,7 +27,7 @@ import org.apache.daffodil.udf.UserDefinedFunctionProvider
*/
class StringFunctionsProvider extends UserDefinedFunctionProvider {
- override def getUserDefinedFunctionClasses = {
+ override def getUserDefinedFunctionClasses: Array[Class[?]] = {
Array(classOf[ReverseWords], classOf[Reverse])
}
}
diff --git
a/daffodil-udf/src/test/scala/org/sbadudfs/udfpexceptions/StringFunctions/StringFunctionsProvider.scala
b/daffodil-udf/src/test/scala/org/sbadudfs/udfpexceptions/StringFunctions/StringFunctionsProvider.scala
index d5ad86fda..1b975aef6 100644
---
a/daffodil-udf/src/test/scala/org/sbadudfs/udfpexceptions/StringFunctions/StringFunctionsProvider.scala
+++
b/daffodil-udf/src/test/scala/org/sbadudfs/udfpexceptions/StringFunctions/StringFunctionsProvider.scala
@@ -31,7 +31,7 @@ class StringFunctionsProvider extends
UserDefinedFunctionProvider {
private val cause: Throwable = None.orNull
) extends Exception(message, cause)
- override def getUserDefinedFunctionClasses = {
+ override def getUserDefinedFunctionClasses: Array[Class[?]] = {
throw new CustomException("UDFP Error!")
Array(classOf[ReverseWords], classOf[Reverse])
}
diff --git
a/daffodil-udf/src/test/scala/org/sbadudfs/udfpexceptions2/StringFunctions/StringFunctionsProvider.scala
b/daffodil-udf/src/test/scala/org/sbadudfs/udfpexceptions2/StringFunctions/StringFunctionsProvider.scala
index febf3e8c7..b8cddf0df 100644
---
a/daffodil-udf/src/test/scala/org/sbadudfs/udfpexceptions2/StringFunctions/StringFunctionsProvider.scala
+++
b/daffodil-udf/src/test/scala/org/sbadudfs/udfpexceptions2/StringFunctions/StringFunctionsProvider.scala
@@ -32,7 +32,7 @@ class StringFunctionsProvider extends
UserDefinedFunctionProvider {
) extends Exception(message, cause)
throw new CustomException("UDFP Error!")
- override def getUserDefinedFunctionClasses = {
+ override def getUserDefinedFunctionClasses: Array[Class[?]] = {
Array(classOf[ReverseWords], classOf[Reverse])
}
}
diff --git
a/daffodil-udf/src/test/scala/org/sgoodudfs/example/IntegerFunctions/IntegerFunctionsProvider.scala
b/daffodil-udf/src/test/scala/org/sgoodudfs/example/IntegerFunctions/IntegerFunctionsProvider.scala
index c534ea1eb..181ae0883 100644
---
a/daffodil-udf/src/test/scala/org/sgoodudfs/example/IntegerFunctions/IntegerFunctionsProvider.scala
+++
b/daffodil-udf/src/test/scala/org/sgoodudfs/example/IntegerFunctions/IntegerFunctionsProvider.scala
@@ -25,7 +25,7 @@ import org.apache.daffodil.udf.UserDefinedFunctionProvider
*
*/
class IntegerFunctionsProvider extends UserDefinedFunctionProvider {
- override def getUserDefinedFunctionClasses = {
+ override def getUserDefinedFunctionClasses: Array[Class[?]] = {
Array(classOf[BoxedAddition], classOf[PrimitivesAddition])
}
}
diff --git
a/daffodil-udf/src/test/scala/org/sgoodudfs/example/StringFunctions/StringFunctionsProvider.scala
b/daffodil-udf/src/test/scala/org/sgoodudfs/example/StringFunctions/StringFunctionsProvider.scala
index 1a059bfca..0d156c940 100644
---
a/daffodil-udf/src/test/scala/org/sgoodudfs/example/StringFunctions/StringFunctionsProvider.scala
+++
b/daffodil-udf/src/test/scala/org/sgoodudfs/example/StringFunctions/StringFunctionsProvider.scala
@@ -25,7 +25,7 @@ import org.apache.daffodil.udf.UserDefinedFunctionProvider
*
*/
class StringFunctionsProvider extends UserDefinedFunctionProvider {
- override def getUserDefinedFunctionClasses = {
+ override def getUserDefinedFunctionClasses: Array[Class[?]] = {
Array(classOf[ReverseWords], classOf[Reverse], classOf[SayHello])
}
}
diff --git
a/daffodil-udf/src/test/scala/org/sgoodudfs/example/SupportedTypesFunctions/SupportedTypesFunctionsProvider.scala
b/daffodil-udf/src/test/scala/org/sgoodudfs/example/SupportedTypesFunctions/SupportedTypesFunctionsProvider.scala
index bdfe49f00..1bf2fd275 100644
---
a/daffodil-udf/src/test/scala/org/sgoodudfs/example/SupportedTypesFunctions/SupportedTypesFunctionsProvider.scala
+++
b/daffodil-udf/src/test/scala/org/sgoodudfs/example/SupportedTypesFunctions/SupportedTypesFunctionsProvider.scala
@@ -25,7 +25,7 @@ import org.apache.daffodil.udf.UserDefinedFunctionProvider
*
*/
class SupportedTypesFunctionsProvider extends UserDefinedFunctionProvider {
- override def getUserDefinedFunctionClasses = {
+ override def getUserDefinedFunctionClasses: Array[Class[?]] = {
Array(
classOf[PrimByteFunc],
classOf[BoxedByteFunc],