summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2012-12-27 03:33:11 -0800
committerSom Snytt <som.snytt@gmail.com>2013-01-09 02:12:35 -0800
commit942f078720cb05c9238913bae8e62900558c2c45 (patch)
tree8c8d58fece2706cf2f8e57b168ea5378f2502c18 /test/files
parent666572261c41cc92b06c03bf4aa260c198240cd8 (diff)
downloadscala-942f078720cb05c9238913bae8e62900558c2c45.tar.gz
scala-942f078720cb05c9238913bae8e62900558c2c45.tar.bz2
scala-942f078720cb05c9238913bae8e62900558c2c45.zip
Repl javap decodes various synthetic names for us (fixing SI-6894)
For instance, javap -app Test is equivalent to javap Test$delayedInit$App with the correct line and iw prepended. This works by taking Test as a name in scope, translating that, and then supplying the suffix. Then javap -fun Test shows Test$$anonfun*, and for member m, javap -fun Test#m shows Test$$anonfun$$m*. This also works for classes and values defined in the repl. javap -fun -raw m shows $line3.$read$$iw$$iw$$anonfun$m$1. E.g., javap -fun scala.Enumeration obviates knowing or guessing scala/Enumeration$$anonfun$scala$Enumeration$$populateNameMap$1.class. Also, scala> :javap -fun scala.Array#concat but still to do is using imported syms. Both files and replout are supported for searching for artifacts. The trigger is detecting the synthetic name (has an interior dollar). Still to do, filter the output on Test#m to show only m. Need a way to explore the list of artifacts; ideally, related symbols would be available reflectively. Prefer companion class to object, otherwise it's not showable; for object, require dollar when both exist. A JavapTest is supplied that is a ReplTest that asserts something about its output instead of printing it.
Diffstat (limited to 'test/files')
-rw-r--r--test/files/run/repl-javap-def.scala17
-rw-r--r--test/files/run/repl-javap-fun.scala16
-rw-r--r--test/files/run/repl-javap-mem.scala19
-rw-r--r--test/files/run/repl-javap-memfun.scala18
-rw-r--r--test/files/run/repl-javap-more-fun.scala17
-rw-r--r--test/files/run/repl-javap-outdir/foo_1.scala6
-rw-r--r--test/files/run/repl-javap-outdir/run-repl_7.scala12
-rw-r--r--test/files/run/repl-javap.scala13
8 files changed, 118 insertions, 0 deletions
diff --git a/test/files/run/repl-javap-def.scala b/test/files/run/repl-javap-def.scala
new file mode 100644
index 0000000000..dbd769613a
--- /dev/null
+++ b/test/files/run/repl-javap-def.scala
@@ -0,0 +1,17 @@
+import scala.tools.partest.JavapTest
+
+object Test extends JavapTest {
+ def code = """
+ |def f = 7
+ |:javap -public -raw f
+ """.stripMargin
+
+ // it should find f wrapped in repl skins. replstiltskin.
+ override def yah(res: Seq[String]) = {
+ // replstiltskin: what be my name?
+ val keywords = List("public", "class", "line")
+ def isLineClass(s: String) = keywords forall (s contains _)
+ def filtered = res filter isLineClass
+ 1 == filtered.size
+ }
+}
diff --git a/test/files/run/repl-javap-fun.scala b/test/files/run/repl-javap-fun.scala
new file mode 100644
index 0000000000..5c9a6b7691
--- /dev/null
+++ b/test/files/run/repl-javap-fun.scala
@@ -0,0 +1,16 @@
+import scala.tools.partest.JavapTest
+
+object Test extends JavapTest {
+ def code = """
+ |object Betty {
+ | List(1,2,3) filter (_ % 2 != 0) map (_ * 2)
+ |}
+ |:javap -fun Betty
+ """.stripMargin
+
+ // two anonfuns of Betty
+ override def yah(res: Seq[String]) = {
+ def filtered = res filter (_ contains "public final class Betty")
+ 2 == filtered.size
+ }
+}
diff --git a/test/files/run/repl-javap-mem.scala b/test/files/run/repl-javap-mem.scala
new file mode 100644
index 0000000000..8db30e835c
--- /dev/null
+++ b/test/files/run/repl-javap-mem.scala
@@ -0,0 +1,19 @@
+import scala.tools.partest.JavapTest
+
+object Test extends JavapTest {
+ def code = """
+ |object Betty {
+ | val ds = List(1,2,3) filter (_ % 2 == 0) map (_ * 3)
+ | def m(vs: List[Int]) = vs filter (_ % 2 != 0) map (_ * 2)
+ |}
+ |:javap Betty#m
+ """.stripMargin
+
+ // filter for requested method member
+ override def yah(res: Seq[String]) = {
+ // cheaply, methods end in arg list
+ val p = """.*m\(.*\);""".r
+ def filtered = res filter (_ match { case p() => true case _ => false })
+ 1 == filtered.size
+ }
+}
diff --git a/test/files/run/repl-javap-memfun.scala b/test/files/run/repl-javap-memfun.scala
new file mode 100644
index 0000000000..d2b4243c8b
--- /dev/null
+++ b/test/files/run/repl-javap-memfun.scala
@@ -0,0 +1,18 @@
+import scala.tools.partest.JavapTest
+
+object Test extends JavapTest {
+ def code = """
+ |object Betty {
+ | List(1,2,3) count (_ % 2 != 0)
+ | def f = List(1,2,3) filter (_ % 2 != 0) map (_ * 2)
+ | def g = List(1,2,3) filter (_ % 2 == 0) map (_ * 3) map (_ + 1)
+ |}
+ |:javap -fun Betty#g
+ """.stripMargin
+
+ // three anonfuns of Betty#g
+ override def yah(res: Seq[String]) = {
+ def filtered = res filter (_ contains "public final class Betty")
+ 3 == filtered.size
+ }
+}
diff --git a/test/files/run/repl-javap-more-fun.scala b/test/files/run/repl-javap-more-fun.scala
new file mode 100644
index 0000000000..e603faf75a
--- /dev/null
+++ b/test/files/run/repl-javap-more-fun.scala
@@ -0,0 +1,17 @@
+import scala.tools.partest.JavapTest
+
+object Test extends JavapTest {
+ def code = """
+ |object Betty {
+ | val ds = List(1,2,3) filter (_ % 2 == 0) map (_ * 3)
+ | def m(vs: List[Int]) = vs filter (_ % 2 != 0) map (_ * 2)
+ |}
+ |:javap -fun Betty
+ """.stripMargin
+
+ // two anonfuns of Betty
+ override def yah(res: Seq[String]) = {
+ def filtered = res filter (_ contains "public final class Betty")
+ 4 == filtered.size
+ }
+}
diff --git a/test/files/run/repl-javap-outdir/foo_1.scala b/test/files/run/repl-javap-outdir/foo_1.scala
new file mode 100644
index 0000000000..9b98e94733
--- /dev/null
+++ b/test/files/run/repl-javap-outdir/foo_1.scala
@@ -0,0 +1,6 @@
+
+package disktest
+
+class Foo {
+ def m(vs: List[Int]) = vs map (_ + 1)
+}
diff --git a/test/files/run/repl-javap-outdir/run-repl_7.scala b/test/files/run/repl-javap-outdir/run-repl_7.scala
new file mode 100644
index 0000000000..dc2c5719ff
--- /dev/null
+++ b/test/files/run/repl-javap-outdir/run-repl_7.scala
@@ -0,0 +1,12 @@
+import scala.tools.partest.JavapTest
+
+object Test extends JavapTest {
+ def code = """
+ |:javap disktest/Foo.class
+ """.stripMargin
+
+ override def yah(res: Seq[String]) = {
+ def filtered = res filter (_ contains "public class disktest.Foo")
+ 1 == filtered.size
+ }
+}
diff --git a/test/files/run/repl-javap.scala b/test/files/run/repl-javap.scala
new file mode 100644
index 0000000000..7a19852d4e
--- /dev/null
+++ b/test/files/run/repl-javap.scala
@@ -0,0 +1,13 @@
+import scala.tools.partest.JavapTest
+
+object Test extends JavapTest {
+ def code = """
+ |case class Betty(i: Int) { def next = Betty(i+1) }
+ |:javap Betty
+ """.stripMargin
+
+ override def yah(res: Seq[String]) = {
+ def filtered = res filter (_ contains "public class Betty")
+ 1 == filtered.size
+ }
+}