Skip to content

Commit 8928303

Browse files
committed
Fix all any2StringAdd and Implicit without Return types Errors
- used `scalafixAll dependency:fix.scala213.Any2StringAdd@org.scala-lang: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
1 parent 5aca152 commit 8928303

File tree

6 files changed

+103
-97
lines changed

6 files changed

+103
-97
lines changed

daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala

+95-90
Original file line numberDiff line numberDiff line change
@@ -160,51 +160,54 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
160160
override def argFormat(name: String): String = "[" + name + "]"
161161
}
162162

163-
implicit def validateConverter = singleArgConverter[ValidationMode.Type]((s: String) => {
164-
import ValidatorPatterns._
165-
s match {
166-
case "on" => ValidationMode.Full
167-
case "limited" => ValidationMode.Limited
168-
case "off" => ValidationMode.Off
169-
case DefaultArgPattern(name, arg) if Validators.isRegistered(name) =>
170-
val config =
171-
if (arg.endsWith(".conf")) ConfigFactory.parseFile(new File(arg))
172-
else ConfigFactory.parseString(s"$name=$arg")
173-
ValidationMode.Custom(Validators.get(name).make(config))
174-
case NoArgsPattern(name) if Validators.isRegistered(name) =>
175-
ValidationMode.Custom(Validators.get(name).make(ConfigFactory.empty))
176-
case _ =>
177-
throw new Exception(
178-
"Unrecognized ValidationMode %s. Must be 'on', 'limited', 'off', or name of spi validator."
179-
.format(s)
180-
)
181-
}
182-
})
163+
implicit def validateConverter: ValueConverter[ValidationMode.Type] =
164+
singleArgConverter[ValidationMode.Type]((s: String) => {
165+
import ValidatorPatterns._
166+
s match {
167+
case "on" => ValidationMode.Full
168+
case "limited" => ValidationMode.Limited
169+
case "off" => ValidationMode.Off
170+
case DefaultArgPattern(name, arg) if Validators.isRegistered(name) =>
171+
val config =
172+
if (arg.endsWith(".conf")) ConfigFactory.parseFile(new File(arg))
173+
else ConfigFactory.parseString(s"$name=$arg")
174+
ValidationMode.Custom(Validators.get(name).make(config))
175+
case NoArgsPattern(name) if Validators.isRegistered(name) =>
176+
ValidationMode.Custom(Validators.get(name).make(ConfigFactory.empty))
177+
case _ =>
178+
throw new Exception(
179+
"Unrecognized ValidationMode %s. Must be 'on', 'limited', 'off', or name of spi validator."
180+
.format(s)
181+
)
182+
}
183+
})
183184

184-
implicit def infosetTypeConverter = singleArgConverter[InfosetType.Type]((s: String) => {
185-
try {
186-
InfosetType.withName(s.toLowerCase)
187-
} catch {
188-
case _: NoSuchElementException =>
189-
throw new Exception(
190-
"Unrecognized infoset type: %s. Must be one of %s".format(
191-
s,
192-
InfosetType.values.mkString(", ")
185+
implicit def infosetTypeConverter: ValueConverter[InfosetType.Type] =
186+
singleArgConverter[InfosetType.Type]((s: String) => {
187+
try {
188+
InfosetType.withName(s.toLowerCase)
189+
} catch {
190+
case _: NoSuchElementException =>
191+
throw new Exception(
192+
"Unrecognized infoset type: %s. Must be one of %s".format(
193+
s,
194+
InfosetType.values.mkString(", ")
195+
)
193196
)
194-
)
195-
}
196-
})
197+
}
198+
})
197199

198-
implicit def implementationConverter = singleArgConverter[TDMLImplementation]((s: String) => {
199-
val optImplementation = TDMLImplementation.optionStringToEnum("implementation", s)
200-
if (!optImplementation.isDefined) {
201-
throw new Exception(
202-
"Unrecognized TDML implementation '%s'. Must be one of %s"
203-
.format(s, TDMLImplementation.values.mkString(", "))
204-
)
205-
}
206-
optImplementation.get
207-
})
200+
implicit def implementationConverter: ValueConverter[TDMLImplementation] =
201+
singleArgConverter[TDMLImplementation]((s: String) => {
202+
val optImplementation = TDMLImplementation.optionStringToEnum("implementation", s)
203+
if (!optImplementation.isDefined) {
204+
throw new Exception(
205+
"Unrecognized TDML implementation '%s'. Must be one of %s"
206+
.format(s, TDMLImplementation.values.mkString(", "))
207+
)
208+
}
209+
optImplementation.get
210+
})
208211

209212
def qnameConvert(s: String): RefQName = {
210213
val eQN = QName.refQNameFromExtendedSyntax(s)
@@ -229,59 +232,61 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
229232
val argType = ArgType.SINGLE
230233
}
231234

232-
implicit def rootNSConverter = org.rogach.scallop.singleArgConverter[RefQName](qnameConvert _)
233-
234-
implicit def fileResourceURIConverter = singleArgConverter[URISchemaSource]((s: String) => {
235-
val optResolved =
236-
try {
237-
val uri =
238-
if (File.separatorChar == '/' || s.startsWith("/")) {
239-
// This is either a non-Windows system or a resource on the classpath. Either way we
240-
// assume it is a valid URI except for things like spaces, which this URI
241-
// constructor converts. We do not specify a schema since this might be a relative
242-
// path
243-
new URI(null, s, null)
244-
} else {
245-
// This is a Windows system, which has complex path resolution and paths that are
246-
// not valid URIs. Try to convert it to a relative URI where possible, otherwise we
247-
// settle for an absolute URI
248-
val p = Paths.get(s)
249-
if (p.isAbsolute() || s.startsWith("\\")) {
250-
// if the Windows path is absolute (i.e. starts with a drive letter and colon) or
251-
// starts with a backslash (which resolves relative to the current drive instead
252-
// of the current working directory), then there is no valid relative URI
253-
// representation, so we just convert it to an absolute URI
254-
p.toUri
235+
implicit def rootNSConverter: ValueConverter[RefQName] =
236+
org.rogach.scallop.singleArgConverter[RefQName](qnameConvert _)
237+
238+
implicit def fileResourceURIConverter: ValueConverter[URISchemaSource] =
239+
singleArgConverter[URISchemaSource]((s: String) => {
240+
val optResolved =
241+
try {
242+
val uri =
243+
if (File.separatorChar == '/' || s.startsWith("/")) {
244+
// This is either a non-Windows system or a resource on the classpath. Either way we
245+
// assume it is a valid URI except for things like spaces, which this URI
246+
// constructor converts. We do not specify a schema since this might be a relative
247+
// path
248+
new URI(null, s, null)
255249
} else {
256-
// this Windows path is relative to the current working directory. We can convert
257-
// it to a relative URI by just switching all the path separators. We do not
258-
// specify a schema since this is a relative path
259-
new URI(null, s.replace('\\', '/'), null)
250+
// This is a Windows system, which has complex path resolution and paths that are
251+
// not valid URIs. Try to convert it to a relative URI where possible, otherwise we
252+
// settle for an absolute URI
253+
val p = Paths.get(s)
254+
if (p.isAbsolute() || s.startsWith("\\")) {
255+
// if the Windows path is absolute (i.e. starts with a drive letter and colon) or
256+
// starts with a backslash (which resolves relative to the current drive instead
257+
// of the current working directory), then there is no valid relative URI
258+
// representation, so we just convert it to an absolute URI
259+
p.toUri
260+
} else {
261+
// this Windows path is relative to the current working directory. We can convert
262+
// it to a relative URI by just switching all the path separators. We do not
263+
// specify a schema since this is a relative path
264+
new URI(null, s.replace('\\', '/'), null)
265+
}
260266
}
267+
// At this point we have a valid URI, which could be absolute or relative, with relative
268+
// URIs resolved from the current working directory. We create a fake contextPath that represents
269+
// a fake file in the current working directory and pass that as the contextSource to the
270+
// resolveSchemaLocation function to find the actual file or resource. This is necessary because
271+
// resolveSchemaLocation expects a context that is a file for diagnostic purposes.
272+
val contextPath = Paths.get("fakeContext.dfdl.xsd")
273+
val contextSource = URISchemaSource(contextPath.toFile, contextPath.toUri)
274+
XMLUtils.resolveSchemaLocation(uri.toString, Some(contextSource))
275+
} catch {
276+
case _: Exception => throw new Exception(s"Could not find file or resource $s")
277+
}
278+
optResolved match {
279+
case Some((uriSchemaSource, relToAbs)) => {
280+
if (relToAbs) {
281+
Logger.log.warn(s"Found relative path on classpath absolutely, did you mean /$s")
261282
}
262-
// At this point we have a valid URI, which could be absolute or relative, with relative
263-
// URIs resolved from the current working directory. We create a fake contextPath that represents
264-
// a fake file in the current working directory and pass that as the contextSource to the
265-
// resolveSchemaLocation function to find the actual file or resource. This is necessary because
266-
// resolveSchemaLocation expects a context that is a file for diagnostic purposes.
267-
val contextPath = Paths.get("fakeContext.dfdl.xsd")
268-
val contextSource = URISchemaSource(contextPath.toFile, contextPath.toUri)
269-
XMLUtils.resolveSchemaLocation(uri.toString, Some(contextSource))
270-
} catch {
271-
case _: Exception => throw new Exception(s"Could not find file or resource $s")
272-
}
273-
optResolved match {
274-
case Some((uriSchemaSource, relToAbs)) => {
275-
if (relToAbs) {
276-
Logger.log.warn(s"Found relative path on classpath absolutely, did you mean /$s")
283+
uriSchemaSource
284+
}
285+
case None => {
286+
throw new Exception(s"Could not find file or resource $s")
277287
}
278-
uriSchemaSource
279-
}
280-
case None => {
281-
throw new Exception(s"Could not find file or resource $s")
282288
}
283-
}
284-
})
289+
})
285290

286291
printedName = "Apache Daffodil"
287292

daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/RepTypeMixin.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ trait RepTypeMixin { self: ElementBase =>
166166
lt.operate(h1, l2).getBoolean,
167167
"Overlapping dfdlx:%s (%s) and dfdlx:%s (%s) found",
168168
if (lt.operate(l1, h1).getBoolean) "repValueRanges" else "repValues",
169-
if (lt.operate(l1, h1).getBoolean) l1.value + " " + h1.value else l1.value,
169+
if (lt.operate(l1, h1).getBoolean) l1.value.toString + " " + h1.value.toString
170+
else l1.value.toString,
170171
if (lt.operate(l2, h2).getBoolean) "repValueRanges" else "repValues",
171-
if (lt.operate(l2, h2).getBoolean) l2.value + " " + h2.value else l2.value
172+
if (lt.operate(l2, h2).getBoolean) l2.value.toString + " " + h2.value.toString
173+
else l2.value.toString
172174
)
173175
(l2, h2)
174176
}

daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/walker/TestDSOMWalker.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ class TestDSOMWalker {
223223
)
224224
val className: String = simpleTypes(index - 1).getSimpleName
225225
val withoutView: String = className.substring(0, className.length - 4)
226-
val fieldName: String = withoutView.charAt(0).toLower + withoutView.substring(1) + "Field"
226+
val fieldName: String =
227+
withoutView.charAt(0).toLower +: (withoutView.substring(1) + "Field")
227228
assertEquals(
228229
s"The $elementIndex${getSuffix(elementIndex)} element in the stack should be named '$fieldName'",
229230
fieldName,

daffodil-io/src/test/scala/org/apache/daffodil/io/TestInputSourceDataInputStream.scala

-2
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ class TestInputSourceDataInputStream {
589589
val m = pat.matcher("")
590590
val cb = CharBuffer.wrap("aaab")
591591
m.reset(cb)
592-
val sb = new StringBuilder
593592
val isMatch = m.lookingAt()
594593
assertTrue(isMatch)
595594
val hitEnd = m.hitEnd
@@ -604,7 +603,6 @@ class TestInputSourceDataInputStream {
604603
assertEqualsTyped[Long](4, end)
605604
val group = m.group
606605
assertEqualsTyped("aaab", group)
607-
sb + group
608606
}
609607

610608
/**

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ object NodeInfo extends Enum {
198198
val cname = super.name
199199
val first = cname(0).toLower
200200
val rest = cname.substring(1)
201-
first + rest
201+
first +: rest
202202
}
203203

204204
def isError: Boolean = false

daffodil-runtime1/src/test/scala/org/apache/daffodil/runtime1/processors/input/TestICU.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class TestICU {
263263
assertEquals(JDouble.POSITIVE_INFINITY, numInf.doubleValue, 0.0)
264264

265265
val ppNInf = new ParsePosition(0)
266-
val numNInf = df.parse(dfs.getMinusSign + dfs.getInfinity, ppNInf)
266+
val numNInf = df.parse(dfs.getMinusSign +: dfs.getInfinity, ppNInf)
267267
assertTrue(numNInf.isInstanceOf[Double])
268268
assertEquals(JDouble.NEGATIVE_INFINITY, numNInf.doubleValue, 0.0)
269269
}

0 commit comments

Comments
 (0)