summaryrefslogtreecommitdiff
path: root/src/repl/scala/tools/nsc/interpreter/Imports.scala
diff options
context:
space:
mode:
authorPrashant Sharma <prashant.s@imaginea.com>2013-09-25 15:27:13 +0530
committerSom Snytt <som.snytt@gmail.com>2013-11-10 23:14:02 -0800
commit1f834cdc9be78c2a6850044a9db24d461b5151ec (patch)
treebfec6675b047a204796b51cdbe814e3a81fd8071 /src/repl/scala/tools/nsc/interpreter/Imports.scala
parent7ecfce1fb8d39275f082aaa3ad4dc0eee197391c (diff)
downloadscala-1f834cdc9be78c2a6850044a9db24d461b5151ec.tar.gz
scala-1f834cdc9be78c2a6850044a9db24d461b5151ec.tar.bz2
scala-1f834cdc9be78c2a6850044a9db24d461b5151ec.zip
SI-7747 Support class based wrappers as alternative through switch -Yrepl-class-based
Refactoring to reduce the number of if-else Fix test.
Diffstat (limited to 'src/repl/scala/tools/nsc/interpreter/Imports.scala')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/Imports.scala24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/Imports.scala b/src/repl/scala/tools/nsc/interpreter/Imports.scala
index ff7bfd432c..c8f9a677b2 100644
--- a/src/repl/scala/tools/nsc/interpreter/Imports.scala
+++ b/src/repl/scala/tools/nsc/interpreter/Imports.scala
@@ -130,13 +130,28 @@ 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)
+ currentImps.clear()
+ }
+
def maybeWrap(names: Name*) = if (names exists currentImps) addWrapper()
+
def wrapBeforeAndAfter[T](op: => T): T = {
addWrapper()
try op finally addWrapper()
@@ -163,7 +178,14 @@ trait Imports {
case x =>
for (sym <- x.definedSymbols) {
maybeWrap(sym.name)
- code append s"import ${x.path}\n"
+ 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"
currentImps += sym.name
}
}