summaryrefslogtreecommitdiff
path: root/test/files/run/showdecl
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-01-28 12:23:47 +0300
committerEugene Burmako <xeno.by@gmail.com>2014-02-14 14:16:42 +0100
commit202eb73b6cd6ebb3e20ff9f0a198c4ea83319851 (patch)
tree1fb59abe86590e8c03baff04099f2eda5bc788ac /test/files/run/showdecl
parentada0252d4494611904c15cc5da72654c1a180a8f (diff)
downloadscala-202eb73b6cd6ebb3e20ff9f0a198c4ea83319851.tar.gz
scala-202eb73b6cd6ebb3e20ff9f0a198c4ea83319851.tar.bz2
scala-202eb73b6cd6ebb3e20ff9f0a198c4ea83319851.zip
adds showDeclaration(sym: Symbol): String
As per Paul’s request, this commit exposes Symbol.defString, although in a different way to ensure consistency with our other prettyprinting facilities provided in the reflection API.
Diffstat (limited to 'test/files/run/showdecl')
-rw-r--r--test/files/run/showdecl/Macros_1.scala30
-rw-r--r--test/files/run/showdecl/Test_2.scala32
2 files changed, 62 insertions, 0 deletions
diff --git a/test/files/run/showdecl/Macros_1.scala b/test/files/run/showdecl/Macros_1.scala
new file mode 100644
index 0000000000..d0493fb97f
--- /dev/null
+++ b/test/files/run/showdecl/Macros_1.scala
@@ -0,0 +1,30 @@
+import scala.reflect.macros.whitebox._
+import scala.language.experimental.macros
+
+object Macros {
+ def impl(c: Context) = {
+ var messages = List[String]()
+ def println(msg: String) = messages :+= msg
+
+ import c.universe._
+ def test(sym: Symbol): Unit = {
+ println(s"uninitialized ${sym.name}: ${showDeclaration(sym)}")
+ sym.typeSignature
+ println(s"initialized ${sym.name}: ${showDeclaration(sym)}")
+ }
+
+ println("compile-time")
+ test(c.mirror.staticClass("D"))
+ test(c.mirror.staticClass("D").typeSignature.member(TermName("x")))
+ test(c.mirror.staticClass("D").typeSignature.member(TermName("y")))
+ test(c.mirror.staticClass("D").typeSignature.member(TermName("z")))
+ test(c.mirror.staticClass("D").typeSignature.member(TermName("t")))
+ test(c.mirror.staticClass("D").typeSignature.member(TypeName("W")))
+ test(c.mirror.staticClass("D").typeSignature.member(TypeName("C")))
+ test(c.mirror.staticClass("D").typeSignature.member(TermName("O")))
+
+ q"..${messages.map(msg => q"println($msg)")}"
+ }
+
+ def foo: Any = macro impl
+} \ No newline at end of file
diff --git a/test/files/run/showdecl/Test_2.scala b/test/files/run/showdecl/Test_2.scala
new file mode 100644
index 0000000000..65ab2f147c
--- /dev/null
+++ b/test/files/run/showdecl/Test_2.scala
@@ -0,0 +1,32 @@
+import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{currentMirror => cm}
+
+object Test extends App {
+ def test(sym: Symbol): Unit = {
+ println(s"autoinitialized ${sym.name}: ${showDeclaration(sym)}")
+ sym.typeSignature
+ println(s"autoinitialized ${sym.name}: ${showDeclaration(sym)}")
+ }
+
+ Macros.foo
+ println("runtime")
+ test(symbolOf[D])
+ test(typeOf[D].member(TermName("x")))
+ test(typeOf[D].member(TermName("y")))
+ test(typeOf[D].member(TermName("z")))
+ test(typeOf[D].member(TermName("t")))
+ test(typeOf[D].member(TypeName("W")))
+ test(typeOf[D].member(TypeName("C")))
+ test(typeOf[D].member(TermName("O")))
+}
+
+class C
+class D extends C {
+ val x = 2
+ lazy val y = 3
+ var z = 4
+ def t[T <: Int](x: D)(y: x.W) = 5
+ type W = String
+ class C extends D
+ object O extends C
+}