summaryrefslogtreecommitdiff
path: root/test/files/run/macro-reify-type/Macros_1.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/run/macro-reify-type/Macros_1.scala')
-rw-r--r--test/files/run/macro-reify-type/Macros_1.scala27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/files/run/macro-reify-type/Macros_1.scala b/test/files/run/macro-reify-type/Macros_1.scala
new file mode 100644
index 0000000000..aeec9fc97c
--- /dev/null
+++ b/test/files/run/macro-reify-type/Macros_1.scala
@@ -0,0 +1,27 @@
+import scala.reflect.macros.Context
+import scala.reflect.runtime.{universe => ru}
+
+object StaticReflect {
+ def method[A](name: String): ru.Type = macro methodImpl[A]
+
+ def methodImpl[A: c.WeakTypeTag](c: Context)(name: c.Expr[String]): c.Expr[ru.Type] = {
+ import c.universe._
+
+ val nameName: TermName = name.tree match {
+ case Literal(Constant(str: String)) => newTermName(str)
+ case _ => c.error(c.enclosingPosition, s"Method name not constant.") ; return reify(ru.NoType)
+ }
+ val clazz = weakTypeOf[A]
+
+ clazz member nameName match {
+ case NoSymbol => c.error(c.enclosingPosition, s"No member called $nameName in $clazz.") ; reify(ru.NoType)
+ case member =>
+ val mtpe = member typeSignatureIn clazz
+ val mtag = c.reifyType(c.runtimeUniverse, Select(c.runtimeUniverse, newTermName("rootMirror")), mtpe)
+ val mtree = Select(mtag, newTermName("tpe"))
+
+ c.Expr[ru.Type](mtree)
+ }
+ }
+
+}