From 38c7dc3bb8b81bebd7dc6a9e092cec0c10d30a9f Mon Sep 17 00:00:00 2001 From: Martin Egri Date: Tue, 13 Jun 2017 15:09:37 +0200 Subject: Disambiguate old-style/new-style macro compiler plugin builds --- examples/macroparadise-example/Hello.scala | 6 ------ examples/macroparadise-example/build/build.scala | 19 ---------------- examples/macroparadise-example/macros/Main.scala | 25 ---------------------- examples/new-style-macros-example/Hello.scala | 6 ++++++ .../new-style-macros-example/build/build.scala | 19 ++++++++++++++++ .../new-style-macros-example/macros/Main.scala | 25 ++++++++++++++++++++++ 6 files changed, 50 insertions(+), 50 deletions(-) delete mode 100644 examples/macroparadise-example/Hello.scala delete mode 100644 examples/macroparadise-example/build/build.scala delete mode 100644 examples/macroparadise-example/macros/Main.scala create mode 100644 examples/new-style-macros-example/Hello.scala create mode 100644 examples/new-style-macros-example/build/build.scala create mode 100644 examples/new-style-macros-example/macros/Main.scala (limited to 'examples') diff --git a/examples/macroparadise-example/Hello.scala b/examples/macroparadise-example/Hello.scala deleted file mode 100644 index 7e04dcb..0000000 --- a/examples/macroparadise-example/Hello.scala +++ /dev/null @@ -1,6 +0,0 @@ -package macroparadise_example -import macros._ - -@Main object Hello{ - println("hello, world!") -} diff --git a/examples/macroparadise-example/build/build.scala b/examples/macroparadise-example/build/build.scala deleted file mode 100644 index 28fb206..0000000 --- a/examples/macroparadise-example/build/build.scala +++ /dev/null @@ -1,19 +0,0 @@ -package macroparadise_example_build -import cbt._ - -trait SharedSettings extends Macroparadise{ - override def defaultScalaVersion = "2.12.2" -} - -class Build(val context: Context) extends SharedSettings{ - override def dependencies = - super.dependencies :+ - new MacroBuild( context.copy( workingDirectory = projectDirectory / "macros" ) ) -} - -class MacroBuild(val context: Context) extends SharedSettings{ - override def dependencies = - super.dependencies :+ - Resolver( mavenCentral ).bindOne( ScalaDependency( "org.scalameta", "scalameta", "1.8.0" ) ) -} - diff --git a/examples/macroparadise-example/macros/Main.scala b/examples/macroparadise-example/macros/Main.scala deleted file mode 100644 index ecdce34..0000000 --- a/examples/macroparadise-example/macros/Main.scala +++ /dev/null @@ -1,25 +0,0 @@ -package macroparadise_example.macros - -import scala.meta._ -import scala.collection.immutable.Seq - -class Main extends scala.annotation.StaticAnnotation { - inline def apply(defn: Any): Any = meta { - defn match { - case q"object $name { ..$stats }" => - MainMacroImpl.expand(name, stats) - case _ => - abort("@main must annotate an object.") - } - } -} - -// This is an example how we can refactor the macro implementation into a utility -// function which can be used for unit testing, see MainUnitTest. -object MainMacroImpl { - def expand(name: Term.Name, stats: Seq[Stat]): Defn.Object = { - val main = q"def main(args: Array[String]): Unit = { ..$stats }" - q"object $name { $main }" - } -} - diff --git a/examples/new-style-macros-example/Hello.scala b/examples/new-style-macros-example/Hello.scala new file mode 100644 index 0000000..7e04dcb --- /dev/null +++ b/examples/new-style-macros-example/Hello.scala @@ -0,0 +1,6 @@ +package macroparadise_example +import macros._ + +@Main object Hello{ + println("hello, world!") +} diff --git a/examples/new-style-macros-example/build/build.scala b/examples/new-style-macros-example/build/build.scala new file mode 100644 index 0000000..2054aba --- /dev/null +++ b/examples/new-style-macros-example/build/build.scala @@ -0,0 +1,19 @@ +package macroparadise_example_build +import cbt._ + +trait SharedSettings extends NewStyleMacros{ + override def defaultScalaVersion = "2.12.2" +} + +class Build(val context: Context) extends SharedSettings{ + override def dependencies = + super.dependencies :+ + new MacroBuild( context.copy( workingDirectory = projectDirectory / "macros" ) ) +} + +class MacroBuild(val context: Context) extends SharedSettings{ + override def dependencies = + super.dependencies :+ + Resolver( mavenCentral ).bindOne( ScalaDependency( "org.scalameta", "scalameta", "1.8.0" ) ) +} + diff --git a/examples/new-style-macros-example/macros/Main.scala b/examples/new-style-macros-example/macros/Main.scala new file mode 100644 index 0000000..ecdce34 --- /dev/null +++ b/examples/new-style-macros-example/macros/Main.scala @@ -0,0 +1,25 @@ +package macroparadise_example.macros + +import scala.meta._ +import scala.collection.immutable.Seq + +class Main extends scala.annotation.StaticAnnotation { + inline def apply(defn: Any): Any = meta { + defn match { + case q"object $name { ..$stats }" => + MainMacroImpl.expand(name, stats) + case _ => + abort("@main must annotate an object.") + } + } +} + +// This is an example how we can refactor the macro implementation into a utility +// function which can be used for unit testing, see MainUnitTest. +object MainMacroImpl { + def expand(name: Term.Name, stats: Seq[Stat]): Defn.Object = { + val main = q"def main(args: Array[String]): Unit = { ..$stats }" + q"object $name { $main }" + } +} + -- cgit v1.2.3