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
|
||||
|
||||
object ClassLoaderCacheTest {
|
||||
implicit class CacheOps(val c: ClassLoaderCache) {
|
||||
extension (c: ClassLoaderCache) {
|
||||
def get(classpath: Seq[File]): ClassLoader = c(classpath.toList)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,8 +153,8 @@ private[sbt] object Clean {
|
|||
case _ => Nil
|
||||
end ToSeqPath
|
||||
|
||||
private implicit class ToSeqPathOps[T](val t: T) extends AnyVal {
|
||||
def toSeqPath(implicit toSeqPath: ToSeqPath[T]): Seq[Path] = toSeqPath(t)
|
||||
extension [T](t: T) {
|
||||
private def toSeqPath(implicit toSeqPath: ToSeqPath[T]): Seq[Path] = toSeqPath(t)
|
||||
}
|
||||
|
||||
@nowarn
|
||||
|
|
|
|||
|
|
@ -1003,7 +1003,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
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
|
||||
|
|
@ -1014,7 +1014,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
*
|
||||
* @return the pretty printed output.
|
||||
*/
|
||||
def show: String = {
|
||||
private def show: String = {
|
||||
val mask = ScopeMask(
|
||||
config = scope.config.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
|
||||
|
|
@ -1049,7 +1049,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
* @return the optional value of the [[SettingKey]] if it is defined at the input
|
||||
* [[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
|
||||
scopedKey.scope match {
|
||||
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
|
||||
* [[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
|
||||
scopedKey.scope match {
|
||||
case scope if scope.task.toOption.isDefined =>
|
||||
|
|
@ -1094,10 +1094,10 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
*
|
||||
* @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
|
||||
|
|
@ -1106,7 +1106,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
* @param prefix the string to prefix the message with
|
||||
* @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 success(message: => String): Unit = logger.success(message)
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import sbt.nio.file.Glob
|
|||
import scala.annotation.{ nowarn, tailrec }
|
||||
|
||||
private[sbt] object WatchTransitiveDependencies {
|
||||
private implicit class SourceOps(val source: Source) {
|
||||
def toGlob: Glob = {
|
||||
extension (source: Source) {
|
||||
private def toGlob: Glob = {
|
||||
val filter = source.includeFilter -- source.excludeFilter
|
||||
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 {
|
||||
def value: Option[FileStamp] = if (e == null) None else Some(e.fold(identity, identity))
|
||||
extension (e: Either[FileStamp, FileStamp]) {
|
||||
private def value: Option[FileStamp] = if (e == null) None else Some(e.fold(identity, identity))
|
||||
}
|
||||
|
||||
private[sbt] class Cache {
|
||||
|
|
|
|||
|
|
@ -53,18 +53,18 @@ object Watch {
|
|||
private val formatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss.SSS")
|
||||
private val timeZone = ZoneId.systemDefault
|
||||
private val timeZoneName = timeZone.getDisplayName(TextStyle.SHORT, Locale.getDefault)
|
||||
private implicit class DurationOps(val d: Duration) extends AnyVal {
|
||||
def finite: FiniteDuration = d match {
|
||||
extension (d: Duration) {
|
||||
private def finite: FiniteDuration = d match {
|
||||
case f: FiniteDuration => f
|
||||
case _ => new FiniteDuration(Long.MaxValue, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
def toEpochString: String = {
|
||||
private def toEpochString: String = {
|
||||
val zdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(d.toMillis), timeZone)
|
||||
s"${formatter.format(zdt)} $timeZoneName"
|
||||
}
|
||||
}
|
||||
private[sbt] implicit class EventOps(val event: Event) extends AnyVal {
|
||||
def toEpochString: String = event.occurredAt.toEpochString
|
||||
extension (event: Event) {
|
||||
private[sbt] def toEpochString: String = event.occurredAt.toEpochString
|
||||
}
|
||||
private[sbt] object Event {
|
||||
trait Impl { self: Event =>
|
||||
|
|
@ -434,8 +434,8 @@ object Watch {
|
|||
private[sbt] def aggregate(events: Seq[(Action, Event)]): Option[(Action, Event)] =
|
||||
if (events.isEmpty) None else Some(events.minBy(_._1))
|
||||
|
||||
private implicit class StringToExec(val s: String) extends AnyVal {
|
||||
def toExec: Exec = Exec(s, None)
|
||||
extension (s: String) {
|
||||
private def toExec: Exec = Exec(s, None)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue