use extension instead of implicit class

This commit is contained in:
xuwei-k 2024-10-22 19:42:47 +09:00 committed by kenji yoshida
parent 16d644a636
commit ec70bae39a
14 changed files with 29 additions and 30 deletions

View File

@ -10,7 +10,7 @@ package sbt.internal.util
package complete
import sbt.io.IO
import Util.{ AnyOps, nil }
import Util.*
object HistoryCommands {
val Start = "!"

View File

@ -68,7 +68,7 @@ object Util {
def nilSeq[A]: Seq[A] = Seq.empty[A]
def none[A]: Option[A] = (None: Option[A])
implicit class AnyOps[A](private val value: A) extends AnyVal {
extension [A](value: A) {
def some: Option[A] = (Some(value): Option[A])
}
}

View File

@ -246,7 +246,7 @@ object Terminal {
}
private[sbt] def set(terminal: Terminal): Terminal = activeTerminal.getAndSet(terminal)
implicit class TerminalOps(private val term: Terminal) extends AnyVal {
extension (term: Terminal) {
def ansi(richString: => String, string: => String): String =
if (term.isAnsiSupported) richString else string
/*

View File

@ -17,7 +17,7 @@ object ShowLines {
def showLines(a: A): Seq[String] = f(a)
}
implicit class ShowLinesOp[A: ShowLines](a: A) {
extension [A: ShowLines](a: A) {
def lines: Seq[String] = implicitly[ShowLines[A]].showLines(a)
}
}

View File

@ -10,7 +10,7 @@ import scala.concurrent.duration.{ Duration, FiniteDuration }
import java.io.File
package object syntax {
implicit class CoursierConfigurationModule(value: CoursierConfiguration.type) {
extension (value: CoursierConfiguration.type) {
@deprecated(
"Legacy cache location support was dropped, this method does nothing.",
"2.0.0-RC6-10"
@ -80,7 +80,7 @@ package object syntax {
)
}
implicit class CoursierConfigurationOp(value: CoursierConfiguration) {
extension (value: CoursierConfiguration) {
def withLog(log: Logger): CoursierConfiguration =
value.withLog(Option(log))
def withSbtScalaOrganization(sbtScalaOrganization: String): CoursierConfiguration =
@ -122,7 +122,7 @@ package object syntax {
value.withRetry(Some((retry._1, retry._2)))
}
implicit class PublicationOp(value: Publication) {
extension (value: Publication) {
def attributes: Attributes =
Attributes(value.`type`, value.classifier)
@ -132,7 +132,7 @@ package object syntax {
.withClassifier(attributes.classifier)
}
implicit class DependencyModule(value: Dependency.type) {
extension (value: Dependency.type) {
def apply(
module: Module,
version: String,
@ -153,7 +153,7 @@ package object syntax {
)
}
implicit class DependencyOp(value: Dependency) {
extension (value: Dependency) {
def attributes: Attributes = value.publication.attributes
def withAttributes(attributes: Attributes): Dependency =
@ -164,7 +164,7 @@ package object syntax {
)
}
implicit class ModuleMatchersModule(value: ModuleMatchers.type) {
extension (value: ModuleMatchers.type) {
def all: ModuleMatchers =
ModuleMatchers(Set.empty, Set.empty)
def only(organization: String, moduleName: String): ModuleMatchers =
@ -177,19 +177,19 @@ package object syntax {
ModuleMatchers(Set.empty, Set(mod), includeByDefault = false)
}
implicit class StrictOp(value: Strict) {
extension (value: Strict) {
def addInclude(include: (String, String)*): Strict =
value.withInclude(value.include ++ include)
def addExclude(exclude: (String, String)*): Strict =
value.withExclude(value.exclude ++ exclude)
}
implicit class AuthenticationModule(value: Authentication.type) {
extension (value: Authentication.type) {
def apply(headers: Seq[(String, String)]): Authentication =
Authentication("", "").withHeaders(headers)
}
implicit class DirectCredentialsModule(value: DirectCredentials.type) {
extension (value: DirectCredentials.type) {
def apply(host: String, username: String, password: String, realm: String): DirectCredentials =
DirectCredentials(host, username, password, Option(realm))
def apply(
@ -202,12 +202,12 @@ package object syntax {
DirectCredentials(host, username, password, Option(realm))
}
implicit class DirectCredentialsOp(value: DirectCredentials) {
extension (value: DirectCredentials) {
def withRealm(realm: String): DirectCredentials =
value.withRealm(Option(realm))
}
implicit class CredentialsModule(value: Credentials.type) {
extension (value: Credentials.type) {
def apply(): DirectCredentials = DirectCredentials()
def apply(host: String, username: String, password: String): DirectCredentials =
DirectCredentials(host, username, password)

View File

@ -12,7 +12,7 @@ import java.io.File
import java.nio.channels.ClosedChannelException
import sbt.internal.inc.{ AnalyzingCompiler, MappedFileConverter, PlainVirtualFile }
import sbt.internal.util.{ DeprecatedJLine, Terminal }
import sbt.internal.util.Terminal.TerminalOps
import sbt.internal.util.Terminal.*
import sbt.util.Logger
import xsbti.compile.{ Compilers, Inputs }

View File

@ -18,7 +18,7 @@ import sbt.io.IO
import sbt.util.Logger
import sbt.ConcurrentRestrictions.Tag
import sbt.protocol.testing._
import sbt.internal.util.Util.{ AnyOps, none }
import sbt.internal.util.Util.*
import sbt.internal.util.{ Terminal => UTerminal }
import xsbti.{ FileConverter, HashedVirtualFileRef }

View File

@ -22,7 +22,7 @@ import sbt.internal.util.complete.{
History => CHistory
}
import sbt.internal.util.Types.{ const, idFun }
import sbt.internal.util.Util.{ AnyOps, nil, nilSeq, none }
import sbt.internal.util.Util.*
import sbt.internal.inc.classpath.ClasspathUtil.toLoader
import sbt.internal.inc.ModuleUtilities
import sbt.internal.client.NetworkClient

View File

@ -26,7 +26,7 @@ private[sbt] object LabeledFunctions {
* @param f the function to extend
* @tparam R the function result type
*/
private[sbt] implicit class Function0Ops[R](val f: () => R) extends AnyVal {
extension [R](f: () => R) {
/**
* Add a label to the function.
@ -42,7 +42,7 @@ private[sbt] object LabeledFunctions {
* @tparam T the input parameter
* @tparam R the function result type
*/
private[sbt] implicit class Function1Ops[T, R](val f: T => R) extends AnyVal {
extension [T, R](f: T => R) {
/**
* Add a label to the function.
@ -59,7 +59,7 @@ private[sbt] object LabeledFunctions {
* @tparam T2 the second function input parameter
* @tparam R the function result type
*/
private[sbt] implicit class Function2Ops[T1, T2, R](val f: (T1, T2) => R) extends AnyVal {
extension [T1, T2, R](f: (T1, T2) => R) {
/**
* Add a label to the function.
@ -77,7 +77,7 @@ private[sbt] object LabeledFunctions {
* @tparam T3 the third function input parameter
* @tparam R the function result type
*/
private[sbt] implicit class Function3Ops[T1, T2, T3, R](val f: (T1, T2, T3) => R) extends AnyVal {
extension [T1, T2, T3, R](f: (T1, T2, T3) => R) {
/**
* Add a label to the function.
@ -96,8 +96,7 @@ private[sbt] object LabeledFunctions {
* @tparam T4 the fourth function input parameter
* @tparam R the function result type
*/
private[sbt] implicit class Function4Ops[T1, T2, T3, T4, R](val f: (T1, T2, T3, T4) => R)
extends AnyVal {
extension [T1, T2, T3, T4, R](f: (T1, T2, T3, T4) => R) {
/**
* Add a label to the function.

View File

@ -13,7 +13,7 @@ import scala.concurrent.duration._
import java.util.concurrent.TimeoutException
object JoinThread {
implicit class ThreadOps(val t: Thread) extends AnyVal {
extension (t: Thread) {
def joinFor(duration: FiniteDuration): Unit = {
val deadline = duration.fromNow
@tailrec def impl(): Unit = {

View File

@ -17,11 +17,11 @@ import sbt.util.Logger
import sbt.librarymanagement.ModuleID
private[internal] object Alternatives {
private[internal] implicit class Alternative[A, B](val f: A => Option[B]) {
extension [A, B](f: A => Option[B]) {
def |(g: A => Option[B]): A => Option[B] = (a: A) => f(a) orElse g(a)
}
}
import Alternatives.Alternative
import Alternatives.*
final class MultiHandler[S, T](
builtIn: S => Option[T],
root: Option[S => Option[T]],

View File

@ -30,7 +30,7 @@ import xsbti.ArtifactInfo
import xsbti.HashedVirtualFileRef
private[sbt] object ClassLoaders {
private implicit class SeqFileOps(val files: Seq[File]) extends AnyVal {
extension (files: Seq[File]) {
def urls: Array[URL] = files.toArray.map(_.toURI.toURL)
}
private val interfaceLoader = classOf[sbt.testing.Framework].getClassLoader

View File

@ -14,7 +14,7 @@ import java.lang.ProcessBuilder.Redirect
import scala.sys.process.Process
import OutputStrategy._
import sbt.internal.util.{ RunningProcesses, Util }
import Util.{ AnyOps, none }
import Util.*
import java.lang.{ ProcessBuilder => JProcessBuilder }
import java.util.Locale

View File

@ -9,7 +9,7 @@
package sbt
import sbt.internal.util.ConsoleAppender.ClearScreenAfterCursor
import sbt.internal.util.Util.{ AnyOps, none }
import sbt.internal.util.Util.*
import scala.annotation.tailrec
object SelectMainClass {