mirror of https://github.com/sbt/sbt.git
Merge pull request #7832 from xuwei-k/extension-implicit-class
[2.x] use `extension` instead of `implicit class`
This commit is contained in:
commit
70c28dac84
|
|
@ -17,7 +17,7 @@ import sbt.internal.classpath.ClassLoaderCache
|
||||||
import sbt.io.IO
|
import sbt.io.IO
|
||||||
|
|
||||||
object ClassLoaderCacheTest {
|
object ClassLoaderCacheTest {
|
||||||
implicit class CacheOps(val c: ClassLoaderCache) {
|
extension (c: ClassLoaderCache) {
|
||||||
def get(classpath: Seq[File]): ClassLoader = c(classpath.toList)
|
def get(classpath: Seq[File]): ClassLoader = c(classpath.toList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,8 +153,8 @@ private[sbt] object Clean {
|
||||||
case _ => Nil
|
case _ => Nil
|
||||||
end ToSeqPath
|
end ToSeqPath
|
||||||
|
|
||||||
private implicit class ToSeqPathOps[T](val t: T) extends AnyVal {
|
extension [T](t: T) {
|
||||||
def toSeqPath(implicit toSeqPath: ToSeqPath[T]): Seq[Path] = toSeqPath(t)
|
private def toSeqPath(implicit toSeqPath: ToSeqPath[T]): Seq[Path] = toSeqPath(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nowarn
|
@nowarn
|
||||||
|
|
|
||||||
|
|
@ -1003,7 +1003,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
||||||
key.get(deprecatedTriggeredMessage).map(Left(_)).getOrElse(Right(default))
|
key.get(deprecatedTriggeredMessage).map(Left(_)).getOrElse(Right(default))
|
||||||
}
|
}
|
||||||
|
|
||||||
private implicit class ScopeOps(val scope: Scope) {
|
extension (scope: Scope) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This shows the [[Scope]] in the format that a user would likely type it in a build
|
* This shows the [[Scope]] in the format that a user would likely type it in a build
|
||||||
|
|
@ -1014,7 +1014,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
||||||
*
|
*
|
||||||
* @return the pretty printed output.
|
* @return the pretty printed output.
|
||||||
*/
|
*/
|
||||||
def show: String = {
|
private def show: String = {
|
||||||
val mask = ScopeMask(
|
val mask = ScopeMask(
|
||||||
config = scope.config.toOption.isDefined,
|
config = scope.config.toOption.isDefined,
|
||||||
task = scope.task.toOption.isDefined,
|
task = scope.task.toOption.isDefined,
|
||||||
|
|
@ -1035,7 +1035,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private implicit class ScopedKeyOps(val scopedKey: ScopedKey[_]) extends AnyVal {
|
extension (scopedKey: ScopedKey[_]) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value for a setting key scoped to the wrapped [[ScopedKey]]. If the task axis is not
|
* Gets the value for a setting key scoped to the wrapped [[ScopedKey]]. If the task axis is not
|
||||||
|
|
@ -1049,7 +1049,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
||||||
* @return the optional value of the [[SettingKey]] if it is defined at the input
|
* @return the optional value of the [[SettingKey]] if it is defined at the input
|
||||||
* [[ScopedKey]] instance's scope or task scope.
|
* [[ScopedKey]] instance's scope or task scope.
|
||||||
*/
|
*/
|
||||||
def get[T](settingKey: SettingKey[T])(implicit extracted: Extracted): Option[T] = {
|
private def get[T](settingKey: SettingKey[T])(implicit extracted: Extracted): Option[T] = {
|
||||||
lazy val taskScope = Project.fillTaskAxis(scopedKey).scope
|
lazy val taskScope = Project.fillTaskAxis(scopedKey).scope
|
||||||
scopedKey.scope match {
|
scopedKey.scope match {
|
||||||
case scope if scope.task.toOption.isDefined =>
|
case scope if scope.task.toOption.isDefined =>
|
||||||
|
|
@ -1071,7 +1071,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
||||||
* @return the optional value of the [[SettingKey]] if it is defined at the input
|
* @return the optional value of the [[SettingKey]] if it is defined at the input
|
||||||
* [[ScopedKey]] instance's scope or task scope.
|
* [[ScopedKey]] instance's scope or task scope.
|
||||||
*/
|
*/
|
||||||
def get[T](taskKey: TaskKey[T])(implicit extracted: Extracted): Option[TaskKey[T]] = {
|
private def get[T](taskKey: TaskKey[T])(implicit extracted: Extracted): Option[TaskKey[T]] = {
|
||||||
lazy val taskScope = Project.fillTaskAxis(scopedKey).scope
|
lazy val taskScope = Project.fillTaskAxis(scopedKey).scope
|
||||||
scopedKey.scope match {
|
scopedKey.scope match {
|
||||||
case scope if scope.task.toOption.isDefined =>
|
case scope if scope.task.toOption.isDefined =>
|
||||||
|
|
@ -1094,10 +1094,10 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
||||||
*
|
*
|
||||||
* @return the pretty printed output.
|
* @return the pretty printed output.
|
||||||
*/
|
*/
|
||||||
def show: String = s"${scopedKey.scope.show} / ${scopedKey.key}"
|
private def show: String = s"${scopedKey.scope.show} / ${scopedKey.key}"
|
||||||
}
|
}
|
||||||
|
|
||||||
private implicit class LoggerOps(val logger: Logger) extends AnyVal {
|
extension (logger: Logger) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a logger that adds a prefix to the messages that it logs. The motivation is so that
|
* Creates a logger that adds a prefix to the messages that it logs. The motivation is so that
|
||||||
|
|
@ -1106,7 +1106,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
||||||
* @param prefix the string to prefix the message with
|
* @param prefix the string to prefix the message with
|
||||||
* @return the wrapped Logger.
|
* @return the wrapped Logger.
|
||||||
*/
|
*/
|
||||||
def withPrefix(prefix: String): Logger = new Logger {
|
private def withPrefix(prefix: String): Logger = new Logger {
|
||||||
override def trace(t: => Throwable): Unit = logger.trace(t)
|
override def trace(t: => Throwable): Unit = logger.trace(t)
|
||||||
|
|
||||||
override def success(message: => String): Unit = logger.success(message)
|
override def success(message: => String): Unit = logger.success(message)
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import sbt.nio.file.Glob
|
||||||
import scala.annotation.{ nowarn, tailrec }
|
import scala.annotation.{ nowarn, tailrec }
|
||||||
|
|
||||||
private[sbt] object WatchTransitiveDependencies {
|
private[sbt] object WatchTransitiveDependencies {
|
||||||
private implicit class SourceOps(val source: Source) {
|
extension (source: Source) {
|
||||||
def toGlob: Glob = {
|
private def toGlob: Glob = {
|
||||||
val filter = source.includeFilter -- source.excludeFilter
|
val filter = source.includeFilter -- source.excludeFilter
|
||||||
Globs.apply(source.base.toPath, source.recursive, filter)
|
Globs.apply(source.base.toPath, source.recursive, filter)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -248,8 +248,8 @@ object FileStamp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private implicit class EitherOps(val e: Either[FileStamp, FileStamp]) extends AnyVal {
|
extension (e: Either[FileStamp, FileStamp]) {
|
||||||
def value: Option[FileStamp] = if (e == null) None else Some(e.fold(identity, identity))
|
private def value: Option[FileStamp] = if (e == null) None else Some(e.fold(identity, identity))
|
||||||
}
|
}
|
||||||
|
|
||||||
private[sbt] class Cache {
|
private[sbt] class Cache {
|
||||||
|
|
|
||||||
|
|
@ -53,18 +53,18 @@ object Watch {
|
||||||
private val formatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss.SSS")
|
private val formatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss.SSS")
|
||||||
private val timeZone = ZoneId.systemDefault
|
private val timeZone = ZoneId.systemDefault
|
||||||
private val timeZoneName = timeZone.getDisplayName(TextStyle.SHORT, Locale.getDefault)
|
private val timeZoneName = timeZone.getDisplayName(TextStyle.SHORT, Locale.getDefault)
|
||||||
private implicit class DurationOps(val d: Duration) extends AnyVal {
|
extension (d: Duration) {
|
||||||
def finite: FiniteDuration = d match {
|
private def finite: FiniteDuration = d match {
|
||||||
case f: FiniteDuration => f
|
case f: FiniteDuration => f
|
||||||
case _ => new FiniteDuration(Long.MaxValue, TimeUnit.MILLISECONDS)
|
case _ => new FiniteDuration(Long.MaxValue, TimeUnit.MILLISECONDS)
|
||||||
}
|
}
|
||||||
def toEpochString: String = {
|
private def toEpochString: String = {
|
||||||
val zdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(d.toMillis), timeZone)
|
val zdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(d.toMillis), timeZone)
|
||||||
s"${formatter.format(zdt)} $timeZoneName"
|
s"${formatter.format(zdt)} $timeZoneName"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private[sbt] implicit class EventOps(val event: Event) extends AnyVal {
|
extension (event: Event) {
|
||||||
def toEpochString: String = event.occurredAt.toEpochString
|
private[sbt] def toEpochString: String = event.occurredAt.toEpochString
|
||||||
}
|
}
|
||||||
private[sbt] object Event {
|
private[sbt] object Event {
|
||||||
trait Impl { self: Event =>
|
trait Impl { self: Event =>
|
||||||
|
|
@ -434,8 +434,8 @@ object Watch {
|
||||||
private[sbt] def aggregate(events: Seq[(Action, Event)]): Option[(Action, Event)] =
|
private[sbt] def aggregate(events: Seq[(Action, Event)]): Option[(Action, Event)] =
|
||||||
if (events.isEmpty) None else Some(events.minBy(_._1))
|
if (events.isEmpty) None else Some(events.minBy(_._1))
|
||||||
|
|
||||||
private implicit class StringToExec(val s: String) extends AnyVal {
|
extension (s: String) {
|
||||||
def toExec: Exec = Exec(s, None)
|
private def toExec: Exec = Exec(s, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue