diff options
author | Paul Phillips <paulp@improving.org> | 2012-10-28 14:27:21 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-11-09 16:48:19 -0700 |
commit | 8da7e37674d771e177445cc0c56eab7b7016c2f2 (patch) | |
tree | 4c66a68fc6ad0ea19a4c4240c3d11f9c8d0be6b1 /src/compiler/scala/tools/nsc/interpreter/Imports.scala | |
parent | 31ed2e8da246da07a3318c34cdfae2ca02740524 (diff) | |
download | scala-8da7e37674d771e177445cc0c56eab7b7016c2f2.tar.gz scala-8da7e37674d771e177445cc0c56eab7b7016c2f2.tar.bz2 scala-8da7e37674d771e177445cc0c56eab7b7016c2f2.zip |
Cleanups to the previous repl commits.
Diffstat (limited to 'src/compiler/scala/tools/nsc/interpreter/Imports.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/Imports.scala | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/Imports.scala b/src/compiler/scala/tools/nsc/interpreter/Imports.scala index 021f07002b..c5048ebfd8 100644 --- a/src/compiler/scala/tools/nsc/interpreter/Imports.scala +++ b/src/compiler/scala/tools/nsc/interpreter/Imports.scala @@ -148,44 +148,42 @@ trait Imports { code append "object %s {\n".format(impname) trailingBraces append "}\n" accessPath append ("." + impname) - - currentImps.clear + currentImps.clear() + } + def maybeWrap(names: Name*) = if (names exists currentImps) addWrapper() + def wrapBeforeAndAfter[T](op: => T): T = { + addWrapper() + try op finally addWrapper() } - - addWrapper() // loop through previous requests, adding imports for each one - for (ReqAndHandler(req, handler) <- reqsToUse) { - handler match { - // If the user entered an import, then just use it; add an import wrapping - // level if the import might conflict with some other import - case x: ImportHandler => - if (x.importsWildcard || currentImps.exists(x.importedNames contains _)) - addWrapper() - - code append (x.member + "\n") - - // give wildcard imports a import wrapper all to their own - if (x.importsWildcard) addWrapper() - else currentImps ++= x.importedNames - - // For other requests, import each defined name. - // import them explicitly instead of with _, so that - // ambiguity errors will not be generated. Also, quote - // the name of the variable, so that we don't need to - // handle quoting keywords separately. - case x => - for (sym <- x.definedSymbols) { - if (currentImps contains sym.name) addWrapper() - - code append (s"import ${x.path}\n") - currentImps += sym.name - } + wrapBeforeAndAfter { + for (ReqAndHandler(req, handler) <- reqsToUse) { + handler match { + // If the user entered an import, then just use it; add an import wrapping + // level if the import might conflict with some other import + case x: ImportHandler if x.importsWildcard => + wrapBeforeAndAfter(code append (x.member + "\n")) + case x: ImportHandler => + maybeWrap(x.importedNames: _*) + code append (x.member + "\n") + currentImps ++= x.importedNames + + // For other requests, import each defined name. + // import them explicitly instead of with _, so that + // ambiguity errors will not be generated. Also, quote + // the name of the variable, so that we don't need to + // handle quoting keywords separately. + case x => + for (sym <- x.definedSymbols) { + maybeWrap(sym.name) + code append s"import ${x.path}\n" + currentImps += sym.name + } + } } } - // add one extra wrapper, to prevent warnings in the common case of - // redefining the value bound in the last interpreter request. - addWrapper() + ComputedImports(code.toString, trailingBraces.toString, accessPath.toString) } |