Skip to content

Commit

Permalink
use SAM type
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jul 9, 2018
1 parent 62954d4 commit ae1fdff
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 41 deletions.
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions internal/util-collection/src/main/scala/sbt/util/Show.scala
Expand Up @@ -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
}
5 changes: 1 addition & 4 deletions main-actions/src/main/scala/sbt/TestResultLogger.scala
Expand Up @@ -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))
Expand Down
25 changes: 9 additions & 16 deletions main-settings/src/main/scala/sbt/Reference.scala
Expand Up @@ -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 =
Expand Down
8 changes: 2 additions & 6 deletions main-settings/src/main/scala/sbt/std/TaskMacro.scala
Expand Up @@ -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)(
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions main/src/main/scala/sbt/Main.scala
Expand Up @@ -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 = {
Expand Down
5 changes: 1 addition & 4 deletions sbt/src/main/scala/AllSyntax.scala
Expand Up @@ -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]
Expand Down

0 comments on commit ae1fdff

Please sign in to comment.