summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-11-10 16:37:36 +0000
committerMartin Odersky <odersky@gmail.com>2011-11-10 16:37:36 +0000
commit7121c6a8db65b20667bcb75e77b72c997afe2fde (patch)
tree53efba92694bf8e0c4ff59ad9766f2a65dd11585
parent7876a574d5d9141230113b6bbeb13f00d072c4f1 (diff)
downloadscala-7121c6a8db65b20667bcb75e77b72c997afe2fde.tar.gz
scala-7121c6a8db65b20667bcb75e77b72c997afe2fde.tar.bz2
scala-7121c6a8db65b20667bcb75e77b72c997afe2fde.zip
(1) Made ReflectionUtils an object, to take its...
(1) Made ReflectionUtils an object, to take its members out of the reflect package. (2) Removed old Type/Symbol/Tree from reflect package. (3) Got scratchpad to work better. Review by extempore.
-rw-r--r--src/compiler/scala/tools/nsc/interactive/REPL.scala4
-rw-r--r--src/compiler/scala/tools/nsc/scratchpad/Executor.scala20
-rw-r--r--src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala3
-rw-r--r--src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala4
-rw-r--r--src/library/scala/reflect/ReflectionUtils.scala4
-rw-r--r--src/library/scala/reflect/package.scala8
6 files changed, 17 insertions, 26 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/REPL.scala b/src/compiler/scala/tools/nsc/interactive/REPL.scala
index 98b6f44e29..ea30ce2516 100644
--- a/src/compiler/scala/tools/nsc/interactive/REPL.scala
+++ b/src/compiler/scala/tools/nsc/interactive/REPL.scala
@@ -141,9 +141,9 @@ object REPL {
// Compile instrumented source
scala.tools.nsc.Main.process(Array(iSourceName, "-verbose", "-d", "/classes"))
// Run instrumented source, inserting all output into stripped source
- println("running "+iSimpleName)
+ println("running "+iFullName)
val si = new SourceInserter(strippedSource.content)
- Executor.execute(iSimpleName, si)
+ Executor.execute(iFullName, si)
println("done")
si.currentContents
}
diff --git a/src/compiler/scala/tools/nsc/scratchpad/Executor.scala b/src/compiler/scala/tools/nsc/scratchpad/Executor.scala
index d16b1e088a..673d5827f6 100644
--- a/src/compiler/scala/tools/nsc/scratchpad/Executor.scala
+++ b/src/compiler/scala/tools/nsc/scratchpad/Executor.scala
@@ -1,8 +1,10 @@
package scala.tools.nsc.scratchpad
import java.io.{PrintStream, OutputStreamWriter, Writer}
-import scala.runtime.ScalaRunTime.replStringOf
+
+import scala.runtime.ScalaRunTime.stringOf
import java.lang.reflect.InvocationTargetException
+import scala.reflect.ReflectionUtils._
object Executor {
@@ -10,15 +12,6 @@ object Executor {
private var currentWriter: CommentWriter = null
- def ultimateCause(ex: Throwable): Throwable = ex match {
- case ex: InvocationTargetException =>
- ultimateCause(ex.getCause)
- case ex: ExceptionInInitializerError =>
- ultimateCause(ex.getCause)
- case ex =>
- ex
- }
-
/** Execute module with given name, redirecting all output to given
* source inserter. Catch all exceptions and print stacktrace of underlying causes.
*/
@@ -35,11 +28,10 @@ object Executor {
Console.setOut(newOut)
Console.setErr(newOut)
try {
- val clazz = Class.forName(name+"$")
- clazz.getField("MODULE$").get(null)
+ singletonInstance(name)
} catch {
case ex: Throwable =>
- ultimateCause(ex) match {
+ unwrapThrowable(ex) match {
case _: StopException => ;
case cause => cause.printStackTrace()
}
@@ -57,7 +49,7 @@ object Executor {
def $stop() = throw new StopException
- def $show(x: Any): String = replStringOf(x, scala.Int.MaxValue)
+ def $show(x: Any): String = stringOf(x, scala.Int.MaxValue)
}
class StopException extends Exception
diff --git a/src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala b/src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala
index 68817f2f64..311aa6e324 100644
--- a/src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala
+++ b/src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala
@@ -21,7 +21,6 @@ object SourceInserter {
(prefixes mkString "\n").toArray
}
}
-
class SourceInserter(contents: Array[Char], start: Int = 0, tabInc: Int = 8) extends Writer {
private var buf = contents
@@ -57,7 +56,7 @@ class SourceInserter(contents: Array[Char], start: Int = 0, tabInc: Int = 8) ext
private def insertChar(ch: Char) = {
// Console.err.print("["+ch+"]")
- buf(offset) = ch.toChar
+ buf(offset) = ch
offset += 1
ch match {
case LF => col = 0
diff --git a/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
index 952b1e4dd2..fda713c5c6 100644
--- a/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
+++ b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
@@ -11,7 +11,7 @@ import java.lang.reflect.{ Constructor, Modifier, Method }
import java.io.{ File => JFile }
import java.net.{ URLClassLoader => JURLClassLoader }
import java.net.URL
-import scala.reflect.unwrapForHandler
+import scala.reflect.ReflectionUtils.unwrapHandler
import ScalaClassLoader._
import scala.util.control.Exception.{ catching }
// import Exceptional.unwrap
@@ -88,7 +88,7 @@ trait ScalaClassLoader extends JClassLoader {
throw new NoSuchMethodException(objectName + ".main is not static")
try asContext(method.invoke(null, Array(arguments.toArray: AnyRef): _*)) // !!! : AnyRef shouldn't be necessary
- catch unwrapForHandler({ case ex => throw ex })
+ catch unwrapHandler({ case ex => throw ex })
}
/** A list comprised of this classloader followed by all its
diff --git a/src/library/scala/reflect/ReflectionUtils.scala b/src/library/scala/reflect/ReflectionUtils.scala
index c2f89102cb..b63a8645de 100644
--- a/src/library/scala/reflect/ReflectionUtils.scala
+++ b/src/library/scala/reflect/ReflectionUtils.scala
@@ -9,7 +9,7 @@ import java.lang.reflect.{ InvocationTargetException, UndeclaredThrowableExcepti
/** A few java-reflection oriented utility functions useful during reflection bootstrapping.
*/
-trait ReflectionUtils {
+object ReflectionUtils {
// Unwraps some chained exceptions which arise during reflective calls.
def unwrapThrowable(x: Throwable): Throwable = x match {
case _: InvocationTargetException | // thrown by reflectively invoked method or constructor
@@ -23,7 +23,7 @@ trait ReflectionUtils {
}
// Transforms an exception handler into one which will only receive the unwrapped
// exceptions (for the values of wrap covered in unwrapThrowable.)
- def unwrapForHandler[T](pf: PartialFunction[Throwable, T]): PartialFunction[Throwable, T] = {
+ def unwrapHandler[T](pf: PartialFunction[Throwable, T]): PartialFunction[Throwable, T] = {
case ex if pf isDefinedAt unwrapThrowable(ex) => pf(unwrapThrowable(ex))
}
diff --git a/src/library/scala/reflect/package.scala b/src/library/scala/reflect/package.scala
index d18924c409..62592baa27 100644
--- a/src/library/scala/reflect/package.scala
+++ b/src/library/scala/reflect/package.scala
@@ -1,22 +1,22 @@
package scala
-package object reflect extends ReflectionUtils {
+package object reflect {
+
// !!! This was a val; we can't throw exceptions that aggressively without breaking
// non-standard environments, e.g. google app engine. I made it a lazy val, but
// I think it would be better yet to throw the exception somewhere else - not during
// initialization, but in response to a doomed attempt to utilize it.
lazy val mirror: api.Mirror = {
// we use (Java) reflection here so that we can keep reflect.runtime and reflect.internals in a seperate jar
- singletonInstance("scala.reflect.runtime.Mirror") collect { case x: api.Mirror => x } getOrElse {
+ ReflectionUtils.singletonInstance("scala.reflect.runtime.Mirror") collect { case x: api.Mirror => x } getOrElse {
throw new UnsupportedOperationException("Scala reflection not available on this platform")
}
}
- /** Uncomment once we got rid of the old Symbols, Types, Trees
type Symbol = mirror.Symbol
type Type = mirror.Type
type Tree = mirror.Tree
- */
+
@deprecated("Use `@scala.beans.BeanDescription` instead", "2.10.0")
type BeanDescription = scala.beans.BeanDescription
@deprecated("Use `@scala.beans.BeanDisplayName` instead", "2.10.0")