Skip to content

Commit 514b82b

Browse files
committed
Refactor the code to avoid duplication and separate concerns
1 parent d8ff9c4 commit 514b82b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/compiler/scala/tools/nsc/interpreter/ILoop.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -591,32 +591,31 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
591591
}
592592
}
593593

594-
def withFile(filename: String)(action: File => Unit) {
595-
val f = File(filename)
594+
def smartPath(path: String) = if (File(path).exists) path else path.trim
595+
596+
def withPath(path: String)(action: File => Unit) {
597+
val f = File(path)
596598

597599
if (f.exists) action(f)
598-
else echo("\"" + filename + "\" does not appear to exist")
600+
else echo("The path '" + f + "' doesn't seem to exist.")
599601
}
600602

601603
def loadCommand(arg: String) = {
602-
val smartArg = if (File(arg).exists) arg else arg.trim
603604
var shouldReplay: Option[String] = None
604-
withFile(smartArg)(f => {
605+
withPath(smartPath(arg))(f => {
605606
interpretAllFrom(f)
606607
shouldReplay = Some(":load " + arg)
607608
})
608609
Result(true, shouldReplay)
609610
}
610611

611612
def addClasspath(arg: String): Unit = {
612-
val f = File(arg).normalize
613-
if (f.exists) {
613+
withPath(File(arg).normalize.path)(f => {
614614
addedClasspath = ClassPath.join(addedClasspath, f.path)
615615
val totalClasspath = ClassPath.join(settings.classpath.value, addedClasspath)
616616
echo("Added '%s'. Your new classpath is:\n\"%s\"".format(f.path, totalClasspath))
617617
replay()
618-
}
619-
else echo("The path '" + f + "' doesn't seem to exist.")
618+
})
620619
}
621620

622621
def powerCmd(): Result = {

0 commit comments

Comments
 (0)