Merge pull request #7317 from xuwei-k/trivial-refactoring

This commit is contained in:
eugene yokota 2023-06-25 11:28:41 -04:00 committed by GitHub
commit 5fc0a4c8d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 25 additions and 24 deletions

View File

@ -83,7 +83,7 @@ class FileExamplesTest extends UnitSpec {
def prefixedPathsOnly: List[String] =
allRelativizedPaths
.filter(_ startsWith withCompletionPrefix)
.withFilter(_ startsWith withCompletionPrefix)
.map(_ substring withCompletionPrefix.length)
def createSampleDirStructure(tempDir: File): Unit = {
@ -92,8 +92,8 @@ class FileExamplesTest extends UnitSpec {
nestedFiles = toChildFiles(childDirectories(1), List("farfile1", "barfile2"))
nestedDirectories = toChildFiles(childDirectories(1), List("fardir1", "bardir2"))
(childDirectories ++ nestedDirectories).map(_.mkdirs())
(childFiles ++ nestedFiles).map(_.createNewFile())
(childDirectories ++ nestedDirectories).foreach(_.mkdirs())
(childFiles ++ nestedFiles).foreach(_.createNewFile())
baseDir = tempDir
}

View File

@ -53,7 +53,7 @@ object StackTrace {
val els = t.getStackTrace()
var i = 0
while ((i < els.size) && include(els(i))) {
while ((i < els.length) && include(els(i))) {
appendElement(els(i))
i += 1
}

View File

@ -76,7 +76,7 @@ object Package {
.orElse(Some(default2010Timestamp))
def timeFromConfiguration(config: Configuration): Option[Long] =
(config.options.collect { case t: FixedTimestamp => t }).headOption match {
config.options.collectFirst { case t: FixedTimestamp => t } match {
case Some(FixedTimestamp(value)) => value
case _ => defaultTimestamp
}

View File

@ -97,7 +97,7 @@ object Sync {
def noDuplicateTargets(relation: Relation[File, File]): Unit = {
val dups = relation.reverseMap
.filter { case (_, srcs) => srcs.size >= 2 && srcs.exists(!_.isDirectory) }
.withFilter { case (_, srcs) => srcs.size >= 2 && srcs.exists(!_.isDirectory) }
.map { case (target, srcs) => "\n\t" + target + "\nfrom\n\t" + srcs.mkString("\n\t\t") }
if (dups.nonEmpty)
sys.error("Duplicate mappings:" + dups.mkString)

View File

@ -164,7 +164,7 @@ object TestResultLogger {
"Canceled" -> canceledCount,
"Pending" -> pendingCount
)
val extra = otherCounts.filter(_._2 > 0).map { case (label, count) => s", $label $count" }
val extra = otherCounts.withFilter(_._2 > 0).map { case (label, count) => s", $label $count" }
val postfix = base + extra.mkString
results.overall match {

View File

@ -33,7 +33,7 @@ private[sbt] object ReadJsonFromInputStream {
*/
var headerBuffer = new Array[Byte](128)
def expandHeaderBuffer(): Unit = {
val newHeaderBuffer = new Array[Byte](headerBuffer.size * 2)
val newHeaderBuffer = new Array[Byte](headerBuffer.length * 2)
headerBuffer.view.zipWithIndex.foreach { case (b, i) => newHeaderBuffer(i) = b }
headerBuffer = newHeaderBuffer
}

View File

@ -185,7 +185,7 @@ object Cross {
case (v, keys) =>
val projects = keys.flatMap(project)
keys.toSeq.flatMap { k =>
project(k).filter(projects.contains).flatMap { p =>
project(k).withFilter(projects.contains).flatMap { p =>
if (p == extracted.currentRef || !projects.contains(extracted.currentRef)) {
val parts = project(k).map(_.project) ++ k.scope.config.toOption.map {
case ConfigKey(n) => n.head.toUpper + n.tail

View File

@ -4204,7 +4204,7 @@ object Classpaths {
if (module.organization == scalaOrg) {
val jarName = module.name + ".jar"
val replaceWith = scalaJars(module.revision).toVector
.filter(_.getName == jarName)
.withFilter(_.getName == jarName)
.map(f => (Artifact(f.getName.stripSuffix(".jar")), f))
if (replaceWith.isEmpty) arts else replaceWith
} else

View File

@ -46,7 +46,7 @@ final case class Extracted(
structure.data.get(inCurrent(key.scope), key.key)
@nowarn
private[this] def inCurrent[T](scope: Scope): Scope =
private[this] def inCurrent(scope: Scope): Scope =
if (scope.project == This) scope in currentRef else scope
/**

View File

@ -478,7 +478,7 @@ object BuiltinCommands {
)(s: State): Parser[(Int, Option[String])] =
verbosityParser ~ selectedParser(s, keepKeys).?
def selectedParser(s: State, keepKeys: AttributeKey[_] => Boolean): Parser[String] =
singleArgument(allTaskAndSettingKeys(s).filter(keepKeys).map(_.label).toSet)
singleArgument(allTaskAndSettingKeys(s).withFilter(keepKeys).map(_.label).toSet)
def verbosityParser: Parser[Int] =
success(1) | ((Space ~ "-") ~> (
'v'.id.+.map(_.size + 1) |

View File

@ -72,7 +72,7 @@ object ScopeFilter {
* static inspections will not show them.
*/
def all(sfilter: => ScopeFilter): Initialize[Seq[T]] = Def.bind(getData) { data =>
data.allScopes.toSeq.filter(sfilter(data)).map(s => Project.inScope(s, i)).join
data.allScopes.toSeq.withFilter(sfilter(data)).map(s => Project.inScope(s, i)).join
}
}
final class TaskKeyAll[T] private[sbt] (i: Initialize[Task[T]]) {
@ -83,7 +83,7 @@ object ScopeFilter {
*/
def all(sfilter: => ScopeFilter): Initialize[Task[Seq[T]]] = Def.bind(getData) { data =>
import std.TaskExtra._
data.allScopes.toSeq.filter(sfilter(data)).map(s => Project.inScope(s, i)).join(_.join)
data.allScopes.toSeq.withFilter(sfilter(data)).map(s => Project.inScope(s, i)).join(_.join)
}
}

View File

@ -126,7 +126,8 @@ object CoursierArtifactsTasks {
// it puts it in all of them. See for example what happens to
// the standalone JAR artifact of the coursier cli module.
def allConfigsIfEmpty(configs: Iterable[ConfigRef]): Iterable[ConfigRef] =
if (configs.isEmpty) ivyConfs.filter(_.isPublic).map(c => ConfigRef(c.name)) else configs
if (configs.isEmpty) ivyConfs.withFilter(_.isPublic).map(c => ConfigRef(c.name))
else configs
val extraSbtArtifactsPublication = for {
artifact <- extraSbtArtifacts

View File

@ -93,7 +93,7 @@ private[sbt] object Clean {
val delete = cleanDelete(scope).value
val targetDir = (scope / target).?.value.map(_.toPath)
targetDir.filter(_ => full).foreach(deleteContents(_, excludeFilter, view, delete))
targetDir.withFilter(_ => full).foreach(deleteContents(_, excludeFilter, view, delete))
(scope / cleanFiles).?.value.getOrElse(Nil).foreach { x =>
if (x.isDirectory) deleteContents(x.toPath, excludeFilter, view, delete)
else delete(x.toPath)

View File

@ -162,7 +162,7 @@ private[sbt] final class CommandExchange {
commandQueue.removeIf { e =>
e.source.map(_.channelName) == Some(c.name) && e.commandLine != Shutdown
}
currentExec.filter(_.source.map(_.channelName) == Some(c.name)).foreach { e =>
currentExec.withFilter(_.source.map(_.channelName) == Some(c.name)).foreach { e =>
Util.ignoreResult(NetworkChannel.cancel(e.execId, e.execId.getOrElse("0"), force = false))
}
try commandQueue.put(Exec(s"${ContinuousCommands.stopWatch} ${c.name}", None))

View File

@ -1049,7 +1049,7 @@ private[sbt] object Load {
// Filter the AutoPlugin settings we included based on which ones are
// intended in the AddSettings.AutoPlugins filter.
def autoPluginSettings(f: AutoPlugins) =
projectPlugins.filter(f.include).flatMap(_.projectSettings)
projectPlugins.withFilter(f.include).flatMap(_.projectSettings)
// Grab all the settings we already loaded from sbt files
def settings(files: Seq[File]): Seq[Setting[_]] = {
if (files.nonEmpty)

View File

@ -184,7 +184,7 @@ private[sbt] object PluginsDebug {
)
lazy val debug = PluginsDebug(context.available)
if (!pluginsThisBuild.contains(plugin)) {
val availableInBuilds: List[URI] = perBuild.toList.filter(_._2(plugin)).map(_._1)
val availableInBuilds: List[URI] = perBuild.toList.withFilter(_._2(plugin)).map(_._1)
val s1 = s"Plugin ${plugin.label} is only available in builds:"
val s2 = availableInBuilds.mkString("\n\t")
val s3 =

View File

@ -53,7 +53,7 @@ object DOT {
// add extra edges from evicted to evicted-by module
val evictedByEdges: Seq[Edge] =
graph.nodes
.filter(_.isEvicted)
.withFilter(_.isEvicted)
.map(m => Edge(m.id, m.id.copy(version = m.evictedByVersion.get)))
// remove edges to new evicted-by module which is now replaced by a chain

View File

@ -29,7 +29,7 @@ object Statistics {
val directDependencies = graph.dependencyMap(moduleId).filterNot(_.isEvicted).map(_.id)
val dependencyStats =
directDependencies.map(statsFor).flatMap(_.transitiveStatsWithSelf).toMap
val selfSize = graph.module(moduleId).flatMap(_.jarFile).filter(_.exists).map(_.length)
val selfSize = graph.module(moduleId).flatMap(_.jarFile).withFilter(_.exists).map(_.length)
val numDirectDependencies = directDependencies.size
val numTransitiveDependencies = dependencyStats.size
val transitiveSize = selfSize.getOrElse(0L) + dependencyStats

View File

@ -257,7 +257,7 @@ private[sbt] case class SbtParser(file: File, lines: Seq[String]) extends Parsed
!(c contains "=")
case _ => false
}
parsedTrees.filter(isBadValDef).foreach { badTree =>
parsedTrees.withFilter(isBadValDef).foreach { badTree =>
// Issue errors
val positionLine = badTree.pos.line
throw new MessageOnlyException(

View File

@ -137,7 +137,7 @@ object DependencyTreeSettings {
versionFilter match {
case Some(version) => GraphModuleId(org, name, version) :: Nil
case None =>
graph.nodes.filter(m => m.id.organization == org && m.id.name == name).map(_.id)
graph.nodes.withFilter(m => m.id.organization == org && m.id.name == name).map(_.id)
}
val graphWidth = asciiGraphWidth.value
val output =

View File

@ -239,7 +239,7 @@ trait TaskExtra extends TaskExtra0 {
def lines: Task[List[String]] = lines0(None)
def lines(sid: String): Task[List[String]] = lines0(Some(sid))
private def lines0[T](sid: Option[String]): Task[List[String]] =
private def lines0(sid: Option[String]): Task[List[String]] =
streams map { s =>
IO.readLines(s.readText(key(in), sid))
}