mirror of https://github.com/sbt/sbt.git
use SAM type
This commit is contained in:
parent
62954d46ea
commit
ae1fdff968
|
|
@ -49,9 +49,7 @@ object Instance {
|
|||
trait Transform[C <: blackbox.Context with Singleton, N[_]] {
|
||||
def apply(in: C#Tree): C#Tree
|
||||
}
|
||||
def idTransform[C <: blackbox.Context with Singleton]: Transform[C, Id] = new Transform[C, Id] {
|
||||
def apply(in: C#Tree): C#Tree = in
|
||||
}
|
||||
def idTransform[C <: blackbox.Context with Singleton]: Transform[C, Id] = in => in
|
||||
|
||||
/**
|
||||
* Implementation of a macro that provides a direct syntax for applicative functors and monads.
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@ trait Show[A] {
|
|||
def show(a: A): String
|
||||
}
|
||||
object Show {
|
||||
def apply[A](f: A => String): Show[A] = new Show[A] { def show(a: A): String = f(a) }
|
||||
def apply[A](f: A => String): Show[A] = a => f(a)
|
||||
|
||||
def fromToString[A]: Show[A] = new Show[A] {
|
||||
def show(a: A): String = a.toString
|
||||
}
|
||||
def fromToString[A]: Show[A] = _.toString
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,10 +58,7 @@ object TestResultLogger {
|
|||
|
||||
/** Creates a `TestResultLogger` using a given function. */
|
||||
def apply(f: (Logger, Output, String) => Unit): TestResultLogger =
|
||||
new TestResultLogger {
|
||||
override def run(log: Logger, results: Output, taskName: String) =
|
||||
f(log, results, taskName)
|
||||
}
|
||||
(log, results, taskName) => f(log, results, taskName)
|
||||
|
||||
/** Creates a `TestResultLogger` that ignores its input and always performs the same logging. */
|
||||
def const(f: Logger => Unit) = apply((l, _, _) => f(l))
|
||||
|
|
|
|||
|
|
@ -58,24 +58,17 @@ object RootProject {
|
|||
def apply(base: File): RootProject = RootProject(IO toURI base)
|
||||
}
|
||||
object Reference {
|
||||
implicit val resolvedReferenceOrdering: Ordering[ResolvedReference] =
|
||||
new Ordering[ResolvedReference] {
|
||||
def compare(a: ResolvedReference, b: ResolvedReference): Int = (a, b) match {
|
||||
case (ba: BuildRef, bb: BuildRef) => buildRefOrdering.compare(ba, bb)
|
||||
case (pa: ProjectRef, pb: ProjectRef) => projectRefOrdering.compare(pa, pb)
|
||||
case (_: BuildRef, _: ProjectRef) => -1
|
||||
case (_: ProjectRef, _: BuildRef) => 1
|
||||
}
|
||||
}
|
||||
implicit val buildRefOrdering: Ordering[BuildRef] = new Ordering[BuildRef] {
|
||||
def compare(a: BuildRef, b: BuildRef): Int = a.build compareTo b.build
|
||||
implicit val resolvedReferenceOrdering: Ordering[ResolvedReference] = {
|
||||
case (ba: BuildRef, bb: BuildRef) => buildRefOrdering.compare(ba, bb)
|
||||
case (pa: ProjectRef, pb: ProjectRef) => projectRefOrdering.compare(pa, pb)
|
||||
case (_: BuildRef, _: ProjectRef) => -1
|
||||
case (_: ProjectRef, _: BuildRef) => 1
|
||||
}
|
||||
implicit val buildRefOrdering: Ordering[BuildRef] = (a, b) => a.build compareTo b.build
|
||||
|
||||
implicit val projectRefOrdering: Ordering[ProjectRef] = new Ordering[ProjectRef] {
|
||||
def compare(a: ProjectRef, b: ProjectRef): Int = {
|
||||
val bc = a.build compareTo b.build
|
||||
if (bc == 0) a.project compareTo b.project else bc
|
||||
}
|
||||
implicit val projectRefOrdering: Ordering[ProjectRef] = (a, b) => {
|
||||
val bc = a.build compareTo b.build
|
||||
if (bc == 0) a.project compareTo b.project else bc
|
||||
}
|
||||
|
||||
def display(ref: Reference): String =
|
||||
|
|
|
|||
|
|
@ -418,9 +418,7 @@ object TaskMacro {
|
|||
private[this] def iInitializeMacro[M[_], T](c: blackbox.Context)(t: c.Expr[T])(
|
||||
f: c.Expr[T] => c.Expr[M[T]]
|
||||
)(implicit tt: c.WeakTypeTag[T], mt: c.WeakTypeTag[M[T]]): c.Expr[Initialize[M[T]]] = {
|
||||
val inner: Transform[c.type, M] = new Transform[c.type, M] {
|
||||
def apply(in: c.Tree): c.Tree = f(c.Expr[T](in)).tree
|
||||
}
|
||||
val inner: Transform[c.type, M] = (in: c.Tree) => f(c.Expr[T](in)).tree
|
||||
val cond = c.Expr[T](conditionInputTaskTree(c)(t.tree))
|
||||
Instance
|
||||
.contImpl[T, M](c, InitializeInstance, InputInitConvert, MixedBuilder, EmptyLinter)(
|
||||
|
|
@ -464,9 +462,7 @@ object TaskMacro {
|
|||
private[this] def iParserMacro[M[_], T](c: blackbox.Context)(t: c.Expr[T])(
|
||||
f: c.Expr[T] => c.Expr[M[T]]
|
||||
)(implicit tt: c.WeakTypeTag[T], mt: c.WeakTypeTag[M[T]]): c.Expr[State => Parser[M[T]]] = {
|
||||
val inner: Transform[c.type, M] = new Transform[c.type, M] {
|
||||
def apply(in: c.Tree): c.Tree = f(c.Expr[T](in)).tree
|
||||
}
|
||||
val inner: Transform[c.type, M] = (in: c.Tree) => f(c.Expr[T](in)).tree
|
||||
Instance.contImpl[T, M](c, ParserInstance, ParserConvert, MixedBuilder, LinterDSL.Empty)(
|
||||
Left(t),
|
||||
inner
|
||||
|
|
|
|||
|
|
@ -120,10 +120,8 @@ object StandardMain {
|
|||
import scalacache.caffeine._
|
||||
private[sbt] lazy val cache: Cache[Any] = CaffeineCache[Any]
|
||||
|
||||
private[sbt] val shutdownHook = new Thread(new Runnable {
|
||||
def run(): Unit = {
|
||||
exchange.shutdown
|
||||
}
|
||||
private[sbt] val shutdownHook = new Thread(() => {
|
||||
exchange.shutdown
|
||||
})
|
||||
|
||||
def runManaged(s: State): xsbti.MainResult = {
|
||||
|
|
|
|||
|
|
@ -10,10 +10,7 @@ package sbt
|
|||
// Todo share this this io.syntax
|
||||
private[sbt] trait IOSyntax0 extends IOSyntax1 {
|
||||
implicit def alternative[A, B](f: A => Option[B]): Alternative[A, B] =
|
||||
new Alternative[A, B] {
|
||||
def |(g: A => Option[B]) =
|
||||
(a: A) => f(a) orElse g(a)
|
||||
}
|
||||
g => a => f(a) orElse g(a)
|
||||
}
|
||||
private[sbt] trait Alternative[A, B] {
|
||||
def |(g: A => Option[B]): A => Option[B]
|
||||
|
|
|
|||
Loading…
Reference in New Issue