summaryrefslogtreecommitdiff
path: root/src/repl/scala/tools/nsc/interpreter/Imports.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-11-10 16:26:59 -0800
committerSom Snytt <som.snytt@gmail.com>2013-11-10 23:22:49 -0800
commit1d3156ca5dc07470212afa016b3ad17b02c27a99 (patch)
treeee1a25d1cc1f9cfb6193074ca561d61c9a187a4b /src/repl/scala/tools/nsc/interpreter/Imports.scala
parent1f834cdc9be78c2a6850044a9db24d461b5151ec (diff)
downloadscala-1d3156ca5dc07470212afa016b3ad17b02c27a99.tar.gz
scala-1d3156ca5dc07470212afa016b3ad17b02c27a99.tar.bz2
scala-1d3156ca5dc07470212afa016b3ad17b02c27a99.zip
SI-7747 Support class based wrappers clean up
Simplified the code paths to just use one of two `Wrapper` types for textual templating. Simplified the class-based template to use the same `$iw` name for the both the class and the wrapper value. In addition, the $read value is an object extending $read, instead of containing an extra instance field, which keeps paths to values the same for both templates. Both styles trigger loading the value object by referencing the value that immediately wraps the user code, although for the class style, inner vals are eager and it would suffice to load the enclosing `$read` object. The proposed template included extra vals for values imported from history, but this is not necessary since such an import is always a stable path. (Or, counter-example to test is welcome.) The test for t5148 is updated as a side effect. Probably internal APIs don't make good test subjects. Modify -Y option message.
Diffstat (limited to 'src/repl/scala/tools/nsc/interpreter/Imports.scala')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/Imports.scala32
1 files changed, 6 insertions, 26 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/Imports.scala b/src/repl/scala/tools/nsc/interpreter/Imports.scala
index c8f9a677b2..5244858a62 100644
--- a/src/repl/scala/tools/nsc/interpreter/Imports.scala
+++ b/src/repl/scala/tools/nsc/interpreter/Imports.scala
@@ -92,7 +92,7 @@ trait Imports {
* last one imported is actually usable.
*/
case class ComputedImports(prepend: String, append: String, access: String)
- protected def importsCode(wanted: Set[Name]): ComputedImports = {
+ protected def importsCode(wanted: Set[Name], wrapper: Request#Wrapper): ComputedImports = {
/** Narrow down the list of requests from which imports
* should be taken. Removes requests which cannot contribute
* useful imports for the specified set of wanted names.
@@ -130,23 +130,10 @@ trait Imports {
// add code for a new object to hold some imports
def addWrapper() {
- if (classBasedWrappers) addClassBasedWrapper()
- else addObjectBasedWrapper()
- }
-
- def addObjectBasedWrapper() {
- val impname = nme.INTERPRETER_IMPORT_WRAPPER
- code append "object %s {\n".format(impname)
- trailingBraces append "}\n"
- accessPath append ("." + impname)
- currentImps.clear()
- }
-
- def addClassBasedWrapper() {
- val impname = nme.INTERPRETER_IMPORT_WRAPPER
- code append "class %sC extends Serializable {\n".format(impname)
- trailingBraces append "}\nval " + impname + " = new " + impname + "C;\n"
- accessPath append ("." + impname)
+ import nme.{ INTERPRETER_IMPORT_WRAPPER => iw }
+ code append (wrapper.prewrap format iw)
+ trailingBraces append wrapper.postwrap
+ accessPath append s".$iw"
currentImps.clear()
}
@@ -178,14 +165,7 @@ trait Imports {
case x =>
for (sym <- x.definedSymbols) {
maybeWrap(sym.name)
- if (classBasedWrappers) {
- if (!code.toString.endsWith(".`" + sym.name + "`;\n")) {
- val valName = "$VAL" + req.lineRep.lineId
- code.append("val " + valName + " = " + req.lineRep.readPath + ".INSTANCE;\n")
- code.append("import " + valName + req.accessPath + ".`" + sym.name + "`;\n")
- }
- } else
- code append s"import ${x.path}\n"
+ code append s"import ${x.path}\n"
currentImps += sym.name
}
}