summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Remi Desjardins <jeanremi.desjardins@gmail.com>2013-07-06 12:34:54 -0700
committerJean-Remi Desjardins <jeanremi.desjardins@gmail.com>2013-07-06 12:34:54 -0700
commit514b82b13e353d07e5ed3339a49c87c6f52456cd (patch)
tree7ffd06e87e42bdf2cca3ab50f0770512f75ed2c2
parentd8ff9c40b89475f20b3e26f46fdfd63ec9ec274c (diff)
downloadscala-514b82b13e353d07e5ed3339a49c87c6f52456cd.tar.gz
scala-514b82b13e353d07e5ed3339a49c87c6f52456cd.tar.bz2
scala-514b82b13e353d07e5ed3339a49c87c6f52456cd.zip
Refactor the code to avoid duplication and separate concerns
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ILoop.scala17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
index e37962c958..c7eecc0940 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
@@ -591,17 +591,18 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
}
- def withFile(filename: String)(action: File => Unit) {
- val f = File(filename)
+ def smartPath(path: String) = if (File(path).exists) path else path.trim
+
+ def withPath(path: String)(action: File => Unit) {
+ val f = File(path)
if (f.exists) action(f)
- else echo("\"" + filename + "\" does not appear to exist")
+ else echo("The path '" + f + "' doesn't seem to exist.")
}
def loadCommand(arg: String) = {
- val smartArg = if (File(arg).exists) arg else arg.trim
var shouldReplay: Option[String] = None
- withFile(smartArg)(f => {
+ withPath(smartPath(arg))(f => {
interpretAllFrom(f)
shouldReplay = Some(":load " + arg)
})
@@ -609,14 +610,12 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
def addClasspath(arg: String): Unit = {
- val f = File(arg).normalize
- if (f.exists) {
+ withPath(File(arg).normalize.path)(f => {
addedClasspath = ClassPath.join(addedClasspath, f.path)
val totalClasspath = ClassPath.join(settings.classpath.value, addedClasspath)
echo("Added '%s'. Your new classpath is:\n\"%s\"".format(f.path, totalClasspath))
replay()
- }
- else echo("The path '" + f + "' doesn't seem to exist.")
+ })
}
def powerCmd(): Result = {