diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-08-27 17:06:13 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-08-27 17:06:13 +0200 |
commit | 41e498adee10c582528b5ee475d6286d365ae9b0 (patch) | |
tree | e3998f6c38b3b2e341366f1808653dc156c029e0 /src | |
parent | c6b6fee65c41a8a1f7b54379e45fc650806aa022 (diff) | |
download | scala-41e498adee10c582528b5ee475d6286d365ae9b0.tar.gz scala-41e498adee10c582528b5ee475d6286d365ae9b0.tar.bz2 scala-41e498adee10c582528b5ee475d6286d365ae9b0.zip |
Exposes ToolBox.classLoader
By giving ToolBox.mirror the correct type and constructing the underlying
mirror from a proper classloader, we improve user experience w.r.t
runtime code generation.
Direct motivator: http://stackoverflow.com/questions/12122939, in which
instances of a toolbox-generated class are accessed with Scala reflection.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/reflect/ToolBox.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/reflect/ToolBoxFactory.scala | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/reflect/ToolBox.scala b/src/compiler/scala/tools/reflect/ToolBox.scala index 2505c1afb7..85e2b6543f 100644 --- a/src/compiler/scala/tools/reflect/ToolBox.scala +++ b/src/compiler/scala/tools/reflect/ToolBox.scala @@ -12,7 +12,7 @@ trait ToolBox[U <: Universe] { /** Underlying mirror of a ToolBox */ - val mirror: MirrorOf[u.type] + val mirror: u.Mirror /** Front end of the toolbox. * diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala index 8cc5a4e531..b658491294 100644 --- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala +++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala @@ -26,7 +26,9 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => private class ToolBoxImpl(val frontEnd: FrontEnd, val options: String) extends ToolBox[U] { toolBoxSelf => val u: factorySelf.u.type = factorySelf.u - val mirror: u.Mirror = factorySelf.mirror + + lazy val classLoader = new AbstractFileClassLoader(virtualDirectory, factorySelf.mirror.classLoader) + lazy val mirror: u.Mirror = u.runtimeMirror(classLoader) class ToolBoxGlobal(settings: scala.tools.nsc.Settings, reporter: Reporter) extends ReflectGlobal(settings, reporter, toolBoxSelf.classLoader) { @@ -327,7 +329,6 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => lazy val importer = compiler.mkImporter(u) lazy val exporter = importer.reverse - lazy val classLoader = new AbstractFileClassLoader(virtualDirectory, mirror.classLoader) def typeCheck(tree: u.Tree, expectedType: u.Type, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): u.Tree = { if (compiler.settings.verbose.value) println("importing "+tree+", expectedType = "+expectedType) |