mirror of https://github.com/sbt/sbt.git
Add Util.ignoreResult
This adds a convenience macro for appending `()` to an expression if it is the last expression in a block that is supposed to return Unit.
This commit is contained in:
parent
52d19d8f0c
commit
e53c8f6f01
|
|
@ -9,6 +9,9 @@ package sbt.internal.util
|
|||
|
||||
import java.util.Locale
|
||||
|
||||
import scala.reflect.macros.blackbox
|
||||
import scala.language.experimental.macros
|
||||
|
||||
object Util {
|
||||
def makeList[T](size: Int, value: T): List[T] = List.fill(size)(value)
|
||||
|
||||
|
|
@ -42,6 +45,8 @@ object Util {
|
|||
|
||||
def quoteIfKeyword(s: String): String = if (ScalaKeywords.values(s)) '`' + s + '`' else s
|
||||
|
||||
def ignoreResult[T](f: => T): Unit = macro Macro.ignore
|
||||
|
||||
lazy val isWindows: Boolean =
|
||||
System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")
|
||||
|
||||
|
|
@ -63,4 +68,7 @@ object Util {
|
|||
implicit class AnyOps[A](private val value: A) extends AnyVal {
|
||||
def some: Option[A] = (Some(value): Option[A])
|
||||
}
|
||||
class Macro(val c: blackbox.Context) {
|
||||
def ignore(f: c.Tree): c.Expr[Unit] = c.universe.reify({ c.Expr[Any](f).splice; () })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue