diff options
Diffstat (limited to 'src/compiler/scala/tools')
-rw-r--r-- | src/compiler/scala/tools/nsc/CompilerCommand.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Settings.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/MutableSettings.scala | 17 |
3 files changed, 25 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index 63cb62ee2e..54bc218912 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -11,6 +11,8 @@ import io.File /** A class representing command line info for scalac */ class CompilerCommand(arguments: List[String], val settings: Settings) { def this(arguments: List[String], error: String => Unit) = this(arguments, new Settings(error)) + def this(arguments: List[String], settings: Settings, error: String => Unit) = this(arguments, settings withErrorFn error) + type Setting = Settings#Setting /** file extensions of files that the compiler can process */ diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index ca99ddf27a..d57d5546fa 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -11,4 +11,10 @@ import settings.MutableSettings */ class Settings(errorFn: String => Unit) extends MutableSettings(errorFn) { def this() = this(Console.println) + + override def withErrorFn(errorFn: String => Unit): Settings = { + val settings = new Settings(errorFn) + copyInto(settings) + settings + } } diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala index 67a556f6f0..b468e7c0af 100644 --- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala @@ -22,6 +22,23 @@ class MutableSettings(val errorFn: String => Unit) with Mutable { type ResultOfTryToSet = List[String] + def withErrorFn(errorFn: String => Unit): MutableSettings = { + val settings = new MutableSettings(errorFn) + copyInto(settings) + settings + } + + protected def copyInto(settings: MutableSettings) { + allSettings foreach { thisSetting => + val otherSetting = settings.allSettings find { _.name == thisSetting.name } + otherSetting foreach { otherSetting => + if (thisSetting.isSetByUser || otherSetting.isSetByUser) { + otherSetting.value = thisSetting.value.asInstanceOf[otherSetting.T] + } + } + } + } + /** Iterates over the arguments applying them to settings where applicable. * Then verifies setting dependencies are met. * |