diff options
author | Paul Phillips <paulp@improving.org> | 2012-02-01 10:21:22 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-02-01 10:27:39 -0800 |
commit | b2a21c4eacdddb0ee59a8c74c8a73e6cc34cb6bc (patch) | |
tree | f9121bcb08a15c93f6bbbebc2d05217d877f1fd6 | |
parent | c0e87de8e9421cc2e03a066f307206f967fe518a (diff) | |
download | scala-b2a21c4eacdddb0ee59a8c74c8a73e6cc34cb6bc.tar.gz scala-b2a21c4eacdddb0ee59a8c74c8a73e6cc34cb6bc.tar.bz2 scala-b2a21c4eacdddb0ee59a8c74c8a73e6cc34cb6bc.zip |
Added getPackage to the repl classloader.
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/IMain.scala | 26 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala b/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala index 3bc4e1cbe1..70fa740eeb 100644 --- a/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala +++ b/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala @@ -20,6 +20,10 @@ class AbstractFileClassLoader(root: AbstractFile, parent: ClassLoader) with ScalaClassLoader { // private val defined = mutable.Map[String, Class[_]]() + + // Widening to public + override def getPackage(name: String) = super.getPackage(name) + override protected def trace = sys.props contains "scala.debug.classloader" diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala index 56bb72ca6f..4ccea8afd6 100644 --- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala +++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala @@ -314,6 +314,26 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends private class TranslatingClassLoader(parent: ClassLoader) extends AbstractFileClassLoader(virtualDirectory, parent) { private[IMain] var traceClassLoading = isReplTrace override protected def trace = super.trace || traceClassLoading + + private val packages = mutable.HashMap[String, Package]() + private def enclosingPackageNames(name: String): List[String] = + (name split '.').inits.toList drop 1 dropRight 1 map (_ mkString ".") reverse + + // Here's what all those params to definePackage are after the package name: + // + // specTitle - The specification title + // specVersion - The specification version + // specVendor - The specification vendor + // implTitle - The implementation title + // implVersion - The implementation version + // implVendor - The implementation vendor + // sealBase - If not null, then this package is sealed with respect to the given code source URL object. Otherwise, the package is not sealed. + private def addPackageNames(name: String) { + enclosingPackageNames(name) filterNot (packages contains _) foreach { p => + packages(p) = definePackage(p, "", "", "", "", "", "", null) + repltrace("Added " + packages(p) + " to repl classloader.") + } + } /** Overridden here to try translating a simple name to the generated * class name if the original attempt fails. This method is used by @@ -328,6 +348,12 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends file } } + override def findClass(name: String): JClass = { + val clazz = super.findClass(name) + if (clazz ne null) + addPackageNames(clazz.getName) + clazz + } } private def makeClassLoader(): AbstractFileClassLoader = new TranslatingClassLoader(parentClassLoader match { |