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 89283039a Fix all any2StringAdd and Implicit without Return types
Errors
89283039a is described below
commit 89283039a9cb9db83a708796b07561706013592a
Author: olabusayoT <[email protected]>
AuthorDate: Tue Feb 11 21:58:02 2025 -0500
Fix all any2StringAdd and Implicit without Return types Errors
- used `scalafixAll
dependency:[email protected]:scala-rewrites:0.1.5`
- required fixing some things by hand like `"" + char + string` -> `char +:
string` or `String.valueOf(...)` -> `_.toString`
- used `sbt scalafix --rules=ExplicitResultTypes
-P:ExplicitResultTypes.onlyImplicits=true
DAFFODIL-2152
---
.../main/scala/org/apache/daffodil/cli/Main.scala | 185 +++++++++++----------
.../daffodil/core/grammar/RepTypeMixin.scala | 6 +-
.../daffodil/core/dsom/walker/TestDSOMWalker.scala | 3 +-
.../io/TestInputSourceDataInputStream.scala | 2 -
.../apache/daffodil/runtime1/dpath/NodeInfo.scala | 2 +-
.../runtime1/processors/input/TestICU.scala | 2 +-
6 files changed, 103 insertions(+), 97 deletions(-)
diff --git a/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
b/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
index 7d8b2fede..6ffc4e72b 100644
--- a/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
+++ b/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
@@ -160,51 +160,54 @@ class CLIConf(arguments: Array[String], stdout:
PrintStream, stderr: PrintStream
override def argFormat(name: String): String = "[" + name + "]"
}
- implicit def validateConverter = singleArgConverter[ValidationMode.Type]((s:
String) => {
- import ValidatorPatterns._
- s match {
- case "on" => ValidationMode.Full
- case "limited" => ValidationMode.Limited
- case "off" => ValidationMode.Off
- case DefaultArgPattern(name, arg) if Validators.isRegistered(name) =>
- val config =
- if (arg.endsWith(".conf")) ConfigFactory.parseFile(new File(arg))
- else ConfigFactory.parseString(s"$name=$arg")
- ValidationMode.Custom(Validators.get(name).make(config))
- case NoArgsPattern(name) if Validators.isRegistered(name) =>
- ValidationMode.Custom(Validators.get(name).make(ConfigFactory.empty))
- case _ =>
- throw new Exception(
- "Unrecognized ValidationMode %s. Must be 'on', 'limited', 'off', or
name of spi validator."
- .format(s)
- )
- }
- })
+ implicit def validateConverter: ValueConverter[ValidationMode.Type] =
+ singleArgConverter[ValidationMode.Type]((s: String) => {
+ import ValidatorPatterns._
+ s match {
+ case "on" => ValidationMode.Full
+ case "limited" => ValidationMode.Limited
+ case "off" => ValidationMode.Off
+ case DefaultArgPattern(name, arg) if Validators.isRegistered(name) =>
+ val config =
+ if (arg.endsWith(".conf")) ConfigFactory.parseFile(new File(arg))
+ else ConfigFactory.parseString(s"$name=$arg")
+ ValidationMode.Custom(Validators.get(name).make(config))
+ case NoArgsPattern(name) if Validators.isRegistered(name) =>
+ ValidationMode.Custom(Validators.get(name).make(ConfigFactory.empty))
+ case _ =>
+ throw new Exception(
+ "Unrecognized ValidationMode %s. Must be 'on', 'limited', 'off',
or name of spi validator."
+ .format(s)
+ )
+ }
+ })
- implicit def infosetTypeConverter = singleArgConverter[InfosetType.Type]((s:
String) => {
- try {
- InfosetType.withName(s.toLowerCase)
- } catch {
- case _: NoSuchElementException =>
- throw new Exception(
- "Unrecognized infoset type: %s. Must be one of %s".format(
- s,
- InfosetType.values.mkString(", ")
+ implicit def infosetTypeConverter: ValueConverter[InfosetType.Type] =
+ singleArgConverter[InfosetType.Type]((s: String) => {
+ try {
+ InfosetType.withName(s.toLowerCase)
+ } catch {
+ case _: NoSuchElementException =>
+ throw new Exception(
+ "Unrecognized infoset type: %s. Must be one of %s".format(
+ s,
+ InfosetType.values.mkString(", ")
+ )
)
- )
- }
- })
+ }
+ })
- implicit def implementationConverter =
singleArgConverter[TDMLImplementation]((s: String) => {
- val optImplementation =
TDMLImplementation.optionStringToEnum("implementation", s)
- if (!optImplementation.isDefined) {
- throw new Exception(
- "Unrecognized TDML implementation '%s'. Must be one of %s"
- .format(s, TDMLImplementation.values.mkString(", "))
- )
- }
- optImplementation.get
- })
+ implicit def implementationConverter: ValueConverter[TDMLImplementation] =
+ singleArgConverter[TDMLImplementation]((s: String) => {
+ val optImplementation =
TDMLImplementation.optionStringToEnum("implementation", s)
+ if (!optImplementation.isDefined) {
+ throw new Exception(
+ "Unrecognized TDML implementation '%s'. Must be one of %s"
+ .format(s, TDMLImplementation.values.mkString(", "))
+ )
+ }
+ optImplementation.get
+ })
def qnameConvert(s: String): RefQName = {
val eQN = QName.refQNameFromExtendedSyntax(s)
@@ -229,59 +232,61 @@ class CLIConf(arguments: Array[String], stdout:
PrintStream, stderr: PrintStream
val argType = ArgType.SINGLE
}
- implicit def rootNSConverter =
org.rogach.scallop.singleArgConverter[RefQName](qnameConvert _)
-
- implicit def fileResourceURIConverter =
singleArgConverter[URISchemaSource]((s: String) => {
- val optResolved =
- try {
- val uri =
- if (File.separatorChar == '/' || s.startsWith("/")) {
- // This is either a non-Windows system or a resource on the
classpath. Either way we
- // assume it is a valid URI except for things like spaces, which
this URI
- // constructor converts. We do not specify a schema since this
might be a relative
- // path
- new URI(null, s, null)
- } else {
- // This is a Windows system, which has complex path resolution and
paths that are
- // not valid URIs. Try to convert it to a relative URI where
possible, otherwise we
- // settle for an absolute URI
- val p = Paths.get(s)
- if (p.isAbsolute() || s.startsWith("\\")) {
- // if the Windows path is absolute (i.e. starts with a drive
letter and colon) or
- // starts with a backslash (which resolves relative to the
current drive instead
- // of the current working directory), then there is no valid
relative URI
- // representation, so we just convert it to an absolute URI
- p.toUri
+ implicit def rootNSConverter: ValueConverter[RefQName] =
+ org.rogach.scallop.singleArgConverter[RefQName](qnameConvert _)
+
+ implicit def fileResourceURIConverter: ValueConverter[URISchemaSource] =
+ singleArgConverter[URISchemaSource]((s: String) => {
+ val optResolved =
+ try {
+ val uri =
+ if (File.separatorChar == '/' || s.startsWith("/")) {
+ // This is either a non-Windows system or a resource on the
classpath. Either way we
+ // assume it is a valid URI except for things like spaces, which
this URI
+ // constructor converts. We do not specify a schema since this
might be a relative
+ // path
+ new URI(null, s, null)
} else {
- // this Windows path is relative to the current working
directory. We can convert
- // it to a relative URI by just switching all the path
separators. We do not
- // specify a schema since this is a relative path
- new URI(null, s.replace('\\', '/'), null)
+ // This is a Windows system, which has complex path resolution
and paths that are
+ // not valid URIs. Try to convert it to a relative URI where
possible, otherwise we
+ // settle for an absolute URI
+ val p = Paths.get(s)
+ if (p.isAbsolute() || s.startsWith("\\")) {
+ // if the Windows path is absolute (i.e. starts with a drive
letter and colon) or
+ // starts with a backslash (which resolves relative to the
current drive instead
+ // of the current working directory), then there is no valid
relative URI
+ // representation, so we just convert it to an absolute URI
+ p.toUri
+ } else {
+ // this Windows path is relative to the current working
directory. We can convert
+ // it to a relative URI by just switching all the path
separators. We do not
+ // specify a schema since this is a relative path
+ new URI(null, s.replace('\\', '/'), null)
+ }
}
+ // At this point we have a valid URI, which could be absolute or
relative, with relative
+ // URIs resolved from the current working directory. We create a
fake contextPath that represents
+ // a fake file in the current working directory and pass that as the
contextSource to the
+ // resolveSchemaLocation function to find the actual file or
resource. This is necessary because
+ // resolveSchemaLocation expects a context that is a file for
diagnostic purposes.
+ val contextPath = Paths.get("fakeContext.dfdl.xsd")
+ val contextSource = URISchemaSource(contextPath.toFile,
contextPath.toUri)
+ XMLUtils.resolveSchemaLocation(uri.toString, Some(contextSource))
+ } catch {
+ case _: Exception => throw new Exception(s"Could not find file or
resource $s")
+ }
+ optResolved match {
+ case Some((uriSchemaSource, relToAbs)) => {
+ if (relToAbs) {
+ Logger.log.warn(s"Found relative path on classpath absolutely, did
you mean /$s")
}
- // At this point we have a valid URI, which could be absolute or
relative, with relative
- // URIs resolved from the current working directory. We create a fake
contextPath that represents
- // a fake file in the current working directory and pass that as the
contextSource to the
- // resolveSchemaLocation function to find the actual file or resource.
This is necessary because
- // resolveSchemaLocation expects a context that is a file for
diagnostic purposes.
- val contextPath = Paths.get("fakeContext.dfdl.xsd")
- val contextSource = URISchemaSource(contextPath.toFile,
contextPath.toUri)
- XMLUtils.resolveSchemaLocation(uri.toString, Some(contextSource))
- } catch {
- case _: Exception => throw new Exception(s"Could not find file or
resource $s")
- }
- optResolved match {
- case Some((uriSchemaSource, relToAbs)) => {
- if (relToAbs) {
- Logger.log.warn(s"Found relative path on classpath absolutely, did
you mean /$s")
+ uriSchemaSource
+ }
+ case None => {
+ throw new Exception(s"Could not find file or resource $s")
}
- uriSchemaSource
- }
- case None => {
- throw new Exception(s"Could not find file or resource $s")
}
- }
- })
+ })
printedName = "Apache Daffodil"
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/RepTypeMixin.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/RepTypeMixin.scala
index f3c1af979..7e76f443f 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/RepTypeMixin.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/RepTypeMixin.scala
@@ -166,9 +166,11 @@ trait RepTypeMixin { self: ElementBase =>
lt.operate(h1, l2).getBoolean,
"Overlapping dfdlx:%s (%s) and dfdlx:%s (%s) found",
if (lt.operate(l1, h1).getBoolean) "repValueRanges" else "repValues",
- if (lt.operate(l1, h1).getBoolean) l1.value + " " + h1.value else
l1.value,
+ if (lt.operate(l1, h1).getBoolean) l1.value.toString + " " +
h1.value.toString
+ else l1.value.toString,
if (lt.operate(l2, h2).getBoolean) "repValueRanges" else "repValues",
- if (lt.operate(l2, h2).getBoolean) l2.value + " " + h2.value else
l2.value
+ if (lt.operate(l2, h2).getBoolean) l2.value.toString + " " +
h2.value.toString
+ else l2.value.toString
)
(l2, h2)
}
diff --git
a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/walker/TestDSOMWalker.scala
b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/walker/TestDSOMWalker.scala
index 0f7bd7a55..aa09110fa 100644
---
a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/walker/TestDSOMWalker.scala
+++
b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/walker/TestDSOMWalker.scala
@@ -223,7 +223,8 @@ class TestDSOMWalker {
)
val className: String = simpleTypes(index - 1).getSimpleName
val withoutView: String = className.substring(0, className.length - 4)
- val fieldName: String = withoutView.charAt(0).toLower +
withoutView.substring(1) + "Field"
+ val fieldName: String =
+ withoutView.charAt(0).toLower +: (withoutView.substring(1) + "Field")
assertEquals(
s"The $elementIndex${getSuffix(elementIndex)} element in the stack
should be named '$fieldName'",
fieldName,
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 ab447a5a5..6792b9978 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
@@ -589,7 +589,6 @@ class TestInputSourceDataInputStream {
val m = pat.matcher("")
val cb = CharBuffer.wrap("aaab")
m.reset(cb)
- val sb = new StringBuilder
val isMatch = m.lookingAt()
assertTrue(isMatch)
val hitEnd = m.hitEnd
@@ -604,7 +603,6 @@ class TestInputSourceDataInputStream {
assertEqualsTyped[Long](4, end)
val group = m.group
assertEqualsTyped("aaab", group)
- sb + group
}
/**
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 5ce59bf1a..6c7b91688 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
@@ -198,7 +198,7 @@ object NodeInfo extends Enum {
val cname = super.name
val first = cname(0).toLower
val rest = cname.substring(1)
- first + rest
+ first +: rest
}
def isError: Boolean = false
diff --git
a/daffodil-runtime1/src/test/scala/org/apache/daffodil/runtime1/processors/input/TestICU.scala
b/daffodil-runtime1/src/test/scala/org/apache/daffodil/runtime1/processors/input/TestICU.scala
index c963b5f87..80238a610 100644
---
a/daffodil-runtime1/src/test/scala/org/apache/daffodil/runtime1/processors/input/TestICU.scala
+++
b/daffodil-runtime1/src/test/scala/org/apache/daffodil/runtime1/processors/input/TestICU.scala
@@ -263,7 +263,7 @@ class TestICU {
assertEquals(JDouble.POSITIVE_INFINITY, numInf.doubleValue, 0.0)
val ppNInf = new ParsePosition(0)
- val numNInf = df.parse(dfs.getMinusSign + dfs.getInfinity, ppNInf)
+ val numNInf = df.parse(dfs.getMinusSign +: dfs.getInfinity, ppNInf)
assertTrue(numNInf.isInstanceOf[Double])
assertEquals(JDouble.NEGATIVE_INFINITY, numNInf.doubleValue, 0.0)
}