mirror of https://github.com/sbt/sbt.git
Add a scripted test that uses macro annotations
This commit is contained in:
parent
18c521dd4b
commit
38b795534a
|
|
@ -0,0 +1,6 @@
|
|||
@hello
|
||||
case class Test(x: Int)
|
||||
|
||||
object Main extends App {
|
||||
Test(3).hello
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import scala.reflect.macros.whitebox.Context
|
||||
import scala.language.experimental.macros
|
||||
import scala.annotation.StaticAnnotation
|
||||
|
||||
object HelloMacro {
|
||||
def impl(c: Context)(annottees: c.Tree*): c.Tree = {
|
||||
import c.universe._
|
||||
|
||||
annottees match {
|
||||
case (classDecl: ClassDef) :: Nil =>
|
||||
val q"$mods class $name[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$bases { $self => ..$body }" = classDecl
|
||||
q"""
|
||||
case class $name(...$paramss) extends ..$bases {
|
||||
..$body
|
||||
def hello = "Hello"
|
||||
}
|
||||
"""
|
||||
|
||||
case _ => c.abort(c.enclosingPosition, "Invalid annottee")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class hello extends StaticAnnotation {
|
||||
def macroTransform(annottees: Any*): Any = macro HelloMacro.impl
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
import sbt._
|
||||
import Keys._
|
||||
|
||||
object BuildSettings {
|
||||
val paradiseVersion = "2.0.1"
|
||||
val buildSettings = Defaults.defaultSettings ++ Seq(
|
||||
version := "1.0.0",
|
||||
scalacOptions ++= Seq(""),
|
||||
scalaVersion := "2.11.4",
|
||||
resolvers += Resolver.sonatypeRepo("snapshots"),
|
||||
resolvers += Resolver.sonatypeRepo("releases"),
|
||||
addCompilerPlugin("org.scalamacros" % "paradise" % paradiseVersion cross CrossVersion.full),
|
||||
incOptions := incOptions.value.withNameHashing(true)
|
||||
)
|
||||
}
|
||||
|
||||
object MyBuild extends Build {
|
||||
import BuildSettings._
|
||||
|
||||
lazy val root: Project = Project(
|
||||
"root",
|
||||
file("."),
|
||||
settings = buildSettings ++ Seq(
|
||||
run <<= run in Compile in core
|
||||
)
|
||||
) aggregate(macros, core)
|
||||
|
||||
lazy val macros: Project = Project(
|
||||
"macros",
|
||||
file("macros"),
|
||||
settings = buildSettings ++ Seq(
|
||||
libraryDependencies <+= (scalaVersion)("org.scala-lang" % "scala-reflect" % _),
|
||||
libraryDependencies ++= (
|
||||
if (scalaVersion.value.startsWith("2.10")) List("org.scalamacros" %% "quasiquotes" % paradiseVersion)
|
||||
else Nil
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
lazy val core: Project = Project(
|
||||
"core",
|
||||
file("core"),
|
||||
settings = buildSettings
|
||||
) dependsOn(macros)
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# The goal of this test is just to make sure that sbt does
|
||||
# not crash when it encounters a macro annotation
|
||||
# See #1655 and #1593
|
||||
> compile
|
||||
Loading…
Reference in New Issue