diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileServer.scala | 11 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompilerCommand.scala | 30 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Main.scala | 19 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/Position.scala | 4 |
4 files changed, 41 insertions, 23 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index 9c3845798e..541aadaffa 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -114,13 +114,10 @@ class StandardCompileServer extends SocketServer { override def displayPrompt = () } - if (command.settings.version.value) - reporter.info(null, versionMsg, true) - else if (command.settings.help.value || command.settings.Xhelp.value) { - if (command.settings.help.value) reporter.info(null, command.usageMsg, true) - if (command.settings.Xhelp.value) reporter.info(null, command.xusageMsg, true) - } - else if (command.files.isEmpty) + if (command.shouldStopWithInfo) { + reporter.info(null, + command.getInfoMessage(newGlobal(command.settings, reporter)), true) + } else if (command.files.isEmpty) reporter.info(null, command.usageMsg, true) else { try { diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index 9ad0bb2539..6f22fb8612 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -66,6 +66,36 @@ class CompilerCommand(arguments: List[String], val settings: Settings, "\n") } + // If any of these settings is set, the compiler shouldn't + // start; an informative message of some sort + // should be printed instead. + // (note: do not add "files.isEmpty" do this list) + val stopSettings=List[(()=>Boolean, + (Global)=>String)]( + (()=> settings.help.value, compiler => + usageMsg + compiler.pluginOptionsHelp + ), + (()=> settings.Xhelp.value, compiler => + xusageMsg + ), + (()=> settings.Yhelp.value, compiler => + yusageMsg + ), + (()=> settings.showPlugins.value, compiler => + compiler.pluginDescriptions + ), + (()=> settings.showPhases.value, compiler => + compiler.phaseDescriptions + ) + ) + + def shouldStopWithInfo = stopSettings.exists({pair => (pair._1)()}) + def getInfoMessage(compiler:Global) = + stopSettings.find({pair => (pair._1)()}) match { + case Some((test,getMessage)) => getMessage(compiler) + case None => "" + } + /** Whether the command was processed okay */ var ok = true diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala index a3ff3b7fa3..74e74ae5f8 100644 --- a/src/compiler/scala/tools/nsc/Main.scala +++ b/src/compiler/scala/tools/nsc/Main.scala @@ -60,24 +60,13 @@ object Main extends AnyRef with EvalLoop { return } - if (command.settings.help.value || command.settings.Xhelp.value || command.settings.Yhelp.value) { - if (command.settings.help.value) { - reporter.info(null, command.usageMsg, true) - reporter.info(null, compiler.pluginOptionsHelp, true) - } - if (command.settings.Xhelp.value) - reporter.info(null, command.xusageMsg, true) - if (command.settings.Yhelp.value) - reporter.info(null, command.yusageMsg, true) - } else if (command.settings.showPlugins.value) - reporter.info(null, compiler.pluginDescriptions, true) - else if (command.settings.showPhases.value) - reporter.info(null, compiler.phaseDescriptions, true) - else { + if (command.shouldStopWithInfo) { + reporter.info(null, command.getInfoMessage(compiler), true) + } else { if (command.settings.resident.value) resident(compiler) else if (command.files.isEmpty) { - reporter.info(null, command.usageMsg, true) + reporter.info(null, command.usageMsg, true) reporter.info(null, compiler.pluginOptionsHelp, true) } else { val run = new compiler.Run diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala index 320ee48e77..142c92e0b2 100644 --- a/src/compiler/scala/tools/nsc/util/Position.scala +++ b/src/compiler/scala/tools/nsc/util/Position.scala @@ -71,7 +71,9 @@ trait Position { } case object NoPosition extends Position -case class FakePos(msg: String) extends Position +case class FakePos(msg: String) extends Position { + override def toString=msg +} case class LinePosition(source0: SourceFile, line0: Int) extends Position { assert(line0 >= 1) |