diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-12-09 17:30:30 +0100 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-12-11 00:15:02 +0100 |
commit | b9a900e5d2f32b87149f7bd4cc7531f327abf5be (patch) | |
tree | b0a3df822a5ed98fd7947d5d1e993df398f8e5e8 /test/files/run/macro-subpatterns/Macro_1.scala | |
parent | 13aa2975bb8437ccdd597020073ee2e52d079f2d (diff) | |
download | scala-b9a900e5d2f32b87149f7bd4cc7531f327abf5be.tar.gz scala-b9a900e5d2f32b87149f7bd4cc7531f327abf5be.tar.bz2 scala-b9a900e5d2f32b87149f7bd4cc7531f327abf5be.zip |
Test usage of SubpatternsAttachment from a macro
Diffstat (limited to 'test/files/run/macro-subpatterns/Macro_1.scala')
-rw-r--r-- | test/files/run/macro-subpatterns/Macro_1.scala | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/files/run/macro-subpatterns/Macro_1.scala b/test/files/run/macro-subpatterns/Macro_1.scala new file mode 100644 index 0000000000..d8e86e27c6 --- /dev/null +++ b/test/files/run/macro-subpatterns/Macro_1.scala @@ -0,0 +1,18 @@ +import scala.reflect.macros.WhiteboxContext +import language.experimental.macros + +object Extractor { + def unapply(x: Any): Any = macro unapplyImpl + def unapplyImpl(c: WhiteboxContext)(x: c.Tree) = { + val st = c.universe.asInstanceOf[reflect.internal.SymbolTable] + import st._ + val subpatterns = x.attachments.get[SubpatternsAttachment].get.patterns + q""" + new { + def isEmpty = false + def get = ${subpatterns.toString} + def unapply(x: Any) = this + }.unapply(${x.asInstanceOf[st.Tree]}) + """.asInstanceOf[c.Tree] + } +} |