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