summaryrefslogtreecommitdiff
path: root/test/files/run/reflection-sanitychecks.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/run/reflection-sanitychecks.scala')
-rw-r--r--test/files/run/reflection-sanitychecks.scala30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/files/run/reflection-sanitychecks.scala b/test/files/run/reflection-sanitychecks.scala
new file mode 100644
index 0000000000..a6a24088a4
--- /dev/null
+++ b/test/files/run/reflection-sanitychecks.scala
@@ -0,0 +1,30 @@
+class C {
+ val foo = 1
+ def bar = 2
+ class C { override def toString = "CC" }
+ object O { override def toString = "CO" }
+}
+
+class D {
+ val foo = 3
+ def bar = 4
+ class C { override def toString = "DC" }
+ object O { override def toString = "DO" }
+}
+
+object Test extends App {
+ import scala.reflect.runtime.universe._
+ import scala.reflect.runtime.{currentMirror => cm}
+ val im = cm.reflect(new C)
+
+ def test(tpe: Type): Unit = {
+ def failsafe(action: => Any): Any = try action catch { case ex: Throwable => ex.toString }
+ println("field: " + failsafe(im.reflectField(tpe.member(newTermName("foo")).asTermSymbol).get))
+ println("method: " + failsafe(im.reflectMethod(tpe.member(newTermName("bar")).asMethodSymbol)()))
+ println("class: " + failsafe(im.reflectClass(tpe.member(newTypeName("C")).asClassSymbol).reflectConstructor(typeOf[C].member(newTypeName("C")).asClassSymbol.typeSignature.member(newTermName("<init>")).asMethodSymbol)()))
+ println("object: " + failsafe(im.reflectModule(tpe.member(newTermName("O")).asModuleSymbol).instance))
+ }
+
+ test(typeOf[C])
+ test(typeOf[D])
+} \ No newline at end of file