summaryrefslogtreecommitdiff
path: root/test
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
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')
-rw-r--r--test/files/run/reflection-allmirrors-tostring.check18
-rw-r--r--test/files/run/reflection-magicsymbols-invoke.check12
-rw-r--r--test/files/run/showdecl.check34
-rw-r--r--test/files/run/showdecl/Macros_1.scala30
-rw-r--r--test/files/run/showdecl/Test_2.scala32
5 files changed, 111 insertions, 15 deletions
diff --git a/test/files/run/reflection-allmirrors-tostring.check b/test/files/run/reflection-allmirrors-tostring.check
index 2a3be29402..3003cce6c0 100644
--- a/test/files/run/reflection-allmirrors-tostring.check
+++ b/test/files/run/reflection-allmirrors-tostring.check
@@ -1,14 +1,14 @@
class mirror for C (bound to null)
module mirror for M (bound to null)
instance mirror for an instance of C
-field mirror for C.f1 (bound to an instance of C)
-field mirror for C.f2 (bound to an instance of C)
-method mirror for C.m1: Int (bound to an instance of C)
-method mirror for C.m2(): Int (bound to an instance of C)
-method mirror for C.m3[T >: String <: Int]: T (bound to an instance of C)
-method mirror for C.m4[A, B <: A[Int]](x: A[B])(implicit y: Int): Nothing (bound to an instance of C)
-method mirror for C.m5(x: => Int, y: Int*): String (bound to an instance of C)
+field mirror for private[this] val f1: Int (bound to an instance of C)
+field mirror for private[this] var f2: Int (bound to an instance of C)
+method mirror for def m1: Int (bound to an instance of C)
+method mirror for def m2(): Int (bound to an instance of C)
+method mirror for def m3[T >: String <: Int]: T (bound to an instance of C)
+method mirror for def m4[A[_], B <: A[Int]](x: A[B])(implicit y: Int): Nothing (bound to an instance of C)
+method mirror for def m5(x: => Int,y: Int*): String (bound to an instance of C)
class mirror for C.C (bound to an instance of C)
module mirror for C.M (bound to an instance of C)
-constructor mirror for C.<init>(): C (bound to null)
-constructor mirror for C.C.<init>(): C.this.C (bound to an instance of C)
+constructor mirror for def <init>(): C (bound to null)
+constructor mirror for def <init>(): C.this.C (bound to an instance of C)
diff --git a/test/files/run/reflection-magicsymbols-invoke.check b/test/files/run/reflection-magicsymbols-invoke.check
index b153ae0470..f580296ae7 100644
--- a/test/files/run/reflection-magicsymbols-invoke.check
+++ b/test/files/run/reflection-magicsymbols-invoke.check
@@ -15,12 +15,12 @@ testing Any.!=: false
testing Any.##: 50
testing Any.==: true
testing Any.asInstanceOf: class scala.ScalaReflectionException: Any.asInstanceOf requires a type argument, it cannot be invoked with mirrors
-testing Any.asInstanceOf: class scala.ScalaReflectionException: scala.Any.asInstanceOf[T0]: T0 takes 0 arguments
+testing Any.asInstanceOf: class scala.ScalaReflectionException: final def asInstanceOf[T0]: T0 takes 0 arguments
testing Any.equals: true
testing Any.getClass: class java.lang.String
testing Any.hashCode: 50
testing Any.isInstanceOf: class scala.ScalaReflectionException: Any.isInstanceOf requires a type argument, it cannot be invoked with mirrors
-testing Any.isInstanceOf: class scala.ScalaReflectionException: scala.Any.isInstanceOf[T0]: Boolean takes 0 arguments
+testing Any.isInstanceOf: class scala.ScalaReflectionException: final def isInstanceOf[T0]: Boolean takes 0 arguments
testing Any.toString: 2
============
AnyVal
@@ -28,7 +28,7 @@ it's important to print the list of AnyVal's members
if some of them change (possibly, adding and/or removing magic symbols), we must update this test
constructor AnyVal: ()AnyVal
method getClass: ()Class[_ <: AnyVal]
-testing AnyVal.<init>: class scala.ScalaReflectionException: unsupported symbol constructor AnyVal when invoking bytecodeless method mirror for scala.AnyVal.<init>(): AnyVal (bound to null)
+testing AnyVal.<init>: class scala.ScalaReflectionException: unsupported symbol constructor AnyVal when invoking bytecodeless method mirror for def <init>(): AnyVal (bound to null)
testing AnyVal.getClass: class scala.ScalaReflectionException: expected a member of class Integer, you provided method scala.AnyVal.getClass
============
AnyRef
@@ -59,9 +59,9 @@ method wait: (x$1: Long, x$2: Int)Unit
testing Object.!=: false
testing Object.##: 50
testing Object.$asInstanceOf: class scala.ScalaReflectionException: AnyRef.$asInstanceOf is an internal method, it cannot be invoked with mirrors
-testing Object.$asInstanceOf: class scala.ScalaReflectionException: java.lang.Object.$asInstanceOf[T0](): T0 takes 0 arguments
+testing Object.$asInstanceOf: class scala.ScalaReflectionException: final def $asInstanceOf[T0](): T0 takes 0 arguments
testing Object.$isInstanceOf: class scala.ScalaReflectionException: AnyRef.$isInstanceOf is an internal method, it cannot be invoked with mirrors
-testing Object.$isInstanceOf: class scala.ScalaReflectionException: java.lang.Object.$isInstanceOf[T0](): Boolean takes 0 arguments
+testing Object.$isInstanceOf: class scala.ScalaReflectionException: final def $isInstanceOf[T0](): Boolean takes 0 arguments
testing Object.==: true
testing Object.clone: class java.lang.CloneNotSupportedException: java.lang.String
testing Object.eq: true
@@ -115,5 +115,5 @@ testing String.+: 23
============
CTM
testing Predef.classOf: class scala.ScalaReflectionException: Predef.classOf is a compile-time function, it cannot be invoked with mirrors
-testing Predef.classOf: class scala.ScalaReflectionException: scala.Predef.classOf[T]: Class[T] takes 0 arguments
+testing Predef.classOf: class scala.ScalaReflectionException: def classOf[T]: Class[T] takes 0 arguments
testing Universe.reify: class scala.ScalaReflectionException: scala.reflect.api.Universe.reify is a macro, i.e. a compile-time function, it cannot be invoked with mirrors
diff --git a/test/files/run/showdecl.check b/test/files/run/showdecl.check
new file mode 100644
index 0000000000..b8d7f94c57
--- /dev/null
+++ b/test/files/run/showdecl.check
@@ -0,0 +1,34 @@
+compile-time
+uninitialized D: class D extends
+initialized D: class D extends C
+uninitialized x: val x: <?>
+initialized x: val x: Int
+uninitialized y: lazy val y: <?>
+initialized y: lazy val y: Int
+uninitialized z: def z: <?>
+initialized z: def z: Int
+uninitialized t: def t: <?>
+initialized t: def t[T <: Int](x: D)(y: x.W): Int
+uninitialized W: type W = String
+initialized W: type W = String
+uninitialized C: class C extends
+initialized C: class C extends D
+uninitialized O: object O
+initialized O: object O
+runtime
+autoinitialized D: class D extends C
+autoinitialized D: class D extends C
+autoinitialized x: val x: Int
+autoinitialized x: val x: Int
+autoinitialized y: lazy val y: Int
+autoinitialized y: lazy val y: Int
+autoinitialized z: def z: Int
+autoinitialized z: def z: Int
+autoinitialized t: def t[T <: Int](x: D)(y: x.W): Int
+autoinitialized t: def t[T <: Int](x: D)(y: x.W): Int
+autoinitialized W: type W = String
+autoinitialized W: type W = String
+autoinitialized C: class C extends D
+autoinitialized C: class C extends D
+autoinitialized O: object O
+autoinitialized O: object O
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
+}