mirror of https://github.com/sbt/sbt.git
[2.x] refactor: Reduce return statements (#8925)
This commit is contained in:
parent
b24ecddbd6
commit
0608a660da
|
|
@ -18,7 +18,6 @@ object EditDistance {
|
|||
* Translated from the java version at http://www.merriampark.com/ld.htm which is declared to be
|
||||
* public domain.
|
||||
*/
|
||||
@SuppressWarnings(Array("scalafix:DisableSyntax"))
|
||||
def levenshtein(
|
||||
s: String,
|
||||
t: String,
|
||||
|
|
@ -33,29 +32,33 @@ object EditDistance {
|
|||
val _ = transposeCost
|
||||
val n = s.length
|
||||
val m = t.length
|
||||
if (n == 0) return m
|
||||
if (m == 0) return n
|
||||
if (n == 0) {
|
||||
m
|
||||
} else if (m == 0) {
|
||||
n
|
||||
} else {
|
||||
val d = Array.ofDim[Int](n + 1, m + 1)
|
||||
0 to n foreach (x => d(x)(0) = x)
|
||||
0 to m foreach (x => d(0)(x) = x)
|
||||
|
||||
val d = Array.ofDim[Int](n + 1, m + 1)
|
||||
0 to n foreach (x => d(x)(0) = x)
|
||||
0 to m foreach (x => d(0)(x) = x)
|
||||
for (i <- 1 to n; s_i = s(i - 1); j <- 1 to m) {
|
||||
val t_j = t(j - 1)
|
||||
val cost =
|
||||
if (s_i == t_j) matchCost else if (lower(s_i) == lower(t_j)) caseCost else subCost
|
||||
|
||||
for (i <- 1 to n; s_i = s(i - 1); j <- 1 to m) {
|
||||
val t_j = t(j - 1)
|
||||
val cost = if (s_i == t_j) matchCost else if (lower(s_i) == lower(t_j)) caseCost else subCost
|
||||
val c1 = d(i - 1)(j) + deleteCost
|
||||
val c2 = d(i)(j - 1) + insertCost
|
||||
val c3 = d(i - 1)(j - 1) + cost
|
||||
|
||||
val c1 = d(i - 1)(j) + deleteCost
|
||||
val c2 = d(i)(j - 1) + insertCost
|
||||
val c3 = d(i - 1)(j - 1) + cost
|
||||
d(i)(j) = c1 min c2 min c3
|
||||
|
||||
d(i)(j) = c1 min c2 min c3
|
||||
|
||||
if (transpositions) {
|
||||
if (i > 1 && j > 1 && s(i - 1) == t(j - 2) && s(i - 2) == t(j - 1))
|
||||
d(i)(j) = d(i)(j) min (d(i - 2)(j - 2) + cost)
|
||||
if (transpositions) {
|
||||
if (i > 1 && j > 1 && s(i - 1) == t(j - 2) && s(i - 2) == t(j - 1))
|
||||
d(i)(j) = d(i)(j) min (d(i - 2)(j - 2) + cost)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d(n)(m)
|
||||
d(n)(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,34 +30,36 @@ object CacheUrlConversion {
|
|||
withForwardSlash
|
||||
}
|
||||
|
||||
@SuppressWarnings(Array("scalafix:DisableSyntax"))
|
||||
def cacheFileToOriginalUrl(fileUrl: String, cacheDir: File): String = {
|
||||
if (!fileUrl.startsWith(FileUrlPrefix)) return fileUrl
|
||||
val filePath = normalizedFilePath(fileUrl)
|
||||
val cachePaths = Seq(
|
||||
cacheDir.getAbsolutePath,
|
||||
cacheDir.getCanonicalPath
|
||||
).distinct.map(p =>
|
||||
normalizePathForComparison(if (p.endsWith("/") || p.endsWith("\\")) p else p + "/")
|
||||
)
|
||||
if (!fileUrl.startsWith(FileUrlPrefix)) {
|
||||
fileUrl
|
||||
} else {
|
||||
val filePath = normalizedFilePath(fileUrl)
|
||||
val cachePaths = Seq(
|
||||
cacheDir.getAbsolutePath,
|
||||
cacheDir.getCanonicalPath
|
||||
).distinct.map(p =>
|
||||
normalizePathForComparison(if (p.endsWith("/") || p.endsWith("\\")) p else p + "/")
|
||||
)
|
||||
|
||||
def extractHttpUrl(relativePath: String): Option[String] = {
|
||||
val protocolSepIndex = relativePath.indexOf('/')
|
||||
if (protocolSepIndex > 0) {
|
||||
val protocol = relativePath.substring(0, protocolSepIndex)
|
||||
val rest = relativePath.substring(protocolSepIndex + 1)
|
||||
Some(s"$protocol://$rest")
|
||||
} else None
|
||||
}
|
||||
|
||||
cachePaths
|
||||
.collectFirst {
|
||||
case cachePath if filePath.startsWith(cachePath) =>
|
||||
val relativePath = filePath.stripPrefix(cachePath)
|
||||
extractHttpUrl(relativePath)
|
||||
def extractHttpUrl(relativePath: String): Option[String] = {
|
||||
val protocolSepIndex = relativePath.indexOf('/')
|
||||
if (protocolSepIndex > 0) {
|
||||
val protocol = relativePath.substring(0, protocolSepIndex)
|
||||
val rest = relativePath.substring(protocolSepIndex + 1)
|
||||
Some(s"$protocol://$rest")
|
||||
} else None
|
||||
}
|
||||
.flatten
|
||||
.getOrElse(s"$UnconvertiblePrefix$filePath")
|
||||
|
||||
cachePaths
|
||||
.collectFirst {
|
||||
case cachePath if filePath.startsWith(cachePath) =>
|
||||
val relativePath = filePath.stripPrefix(cachePath)
|
||||
extractHttpUrl(relativePath)
|
||||
}
|
||||
.flatten
|
||||
.getOrElse(s"$UnconvertiblePrefix$filePath")
|
||||
}
|
||||
}
|
||||
|
||||
def isPortableUrl(url: String): Boolean =
|
||||
|
|
|
|||
|
|
@ -240,18 +240,19 @@ private[sbt] object PomGenerator:
|
|||
(scope, optional)
|
||||
|
||||
/** Convert Ivy-style dynamic versions to Maven range format. */
|
||||
@SuppressWarnings(Array("scalafix:DisableSyntax"))
|
||||
private def convertVersion(version: String): String =
|
||||
if version == null then null
|
||||
else if version.endsWith("+") then
|
||||
val base = version.stripSuffix("+").stripSuffix(".")
|
||||
val parts = base.split('.')
|
||||
if parts.nonEmpty then
|
||||
val last =
|
||||
try parts.last.toInt + 1
|
||||
catch case _: NumberFormatException => return version
|
||||
val upper = (parts.init :+ last.toString).mkString(".")
|
||||
s"[$base,$upper)"
|
||||
parts.last.toIntOption.map(_ + 1) match {
|
||||
case Some(last) =>
|
||||
val upper = (parts.init :+ last.toString).mkString(".")
|
||||
s"[$base,$upper)"
|
||||
case None =>
|
||||
version
|
||||
}
|
||||
else version
|
||||
else if version == "latest.integration" || version == "latest.release" then ""
|
||||
else version
|
||||
|
|
|
|||
|
|
@ -70,21 +70,21 @@ object Runner:
|
|||
if opts.jvmClient then s = s :+ "--client"
|
||||
s
|
||||
|
||||
@SuppressWarnings(Array("scalafix:DisableSyntax"))
|
||||
def runNativeClient(sbtBinDir: File, scriptPath: String, opts: LauncherOptions): Int =
|
||||
val sbtn = new File(sbtBinDir, "sbtn-x86_64-pc-win32.exe")
|
||||
if !sbtn.isFile then
|
||||
System.err.println("[error] sbtn-x86_64-pc-win32.exe not found in " + sbtBinDir)
|
||||
return 1
|
||||
val args = Seq("--sbt-script=" + scriptPath.replace(" ", "%20")) ++
|
||||
(if opts.verbose then Seq("-v") else Nil) ++
|
||||
opts.residual
|
||||
val cmd = sbtn.getAbsolutePath +: args
|
||||
if opts.verbose then
|
||||
System.err.println("# running native client")
|
||||
cmd.foreach(a => System.err.println(a))
|
||||
val proc = Process(cmd, None, "SBT_SCRIPT" -> scriptPath)
|
||||
proc.!
|
||||
1
|
||||
else
|
||||
val args = Seq("--sbt-script=" + scriptPath.replace(" ", "%20")) ++
|
||||
(if opts.verbose then Seq("-v") else Nil) ++
|
||||
opts.residual
|
||||
val cmd = sbtn.getAbsolutePath +: args
|
||||
if opts.verbose then
|
||||
System.err.println("# running native client")
|
||||
cmd.foreach(a => System.err.println(a))
|
||||
val proc = Process(cmd, None, "SBT_SCRIPT" -> scriptPath)
|
||||
proc.!
|
||||
|
||||
def runJvm(
|
||||
javaCmd: String,
|
||||
|
|
|
|||
Loading…
Reference in New Issue