summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-02-17 18:26:12 +0100
committerJason Zaugg <jzaugg@gmail.com>2014-02-17 19:22:01 +0100
commit55549bfa41f4a19c9556b71791de35875e8229dc (patch)
treec2e96055269bafa5e7e84bf1ab6c230d463c31fc
parent1b1461fed759c8f937c01fe2e7d3922ab67df700 (diff)
downloadscala-55549bfa41f4a19c9556b71791de35875e8229dc.tar.gz
scala-55549bfa41f4a19c9556b71791de35875e8229dc.tar.bz2
scala-55549bfa41f4a19c9556b71791de35875e8229dc.zip
Expose a means to disable boolean settings
Enables `-Yboolean-setting:{true,false}`. This will be exploited in the next commit to enable one to turn off a single component of a group setting, such as `-Xlint` or `-optimize`.
-rw-r--r--src/compiler/scala/tools/nsc/settings/MutableSettings.scala11
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala2
-rw-r--r--test/junit/scala/tools/nsc/settings/SettingsTest.scala28
3 files changed, 40 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
index 0536be92cf..a8421c8b15 100644
--- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
@@ -438,6 +438,17 @@ class MutableSettings(val errorFn: String => Unit)
override def tryToSetFromPropertyValue(s : String) { // used from ide
value = s.equalsIgnoreCase("true")
}
+ override def tryToSetColon(args: List[String]) = args match {
+ case Nil => tryToSet(Nil)
+ case List(x) =>
+ if (x.equalsIgnoreCase("true")) {
+ value = true
+ Some(Nil)
+ } else if (x.equalsIgnoreCase("false")) {
+ value = false
+ Some(Nil)
+ } else errorAndValue("'" + x + "' is not a valid choice for '" + name + "'", None)
+ }
}
/** A special setting for accumulating arguments like -Dfoo=bar. */
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index a385a31165..57aa8243b6 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -20,7 +20,7 @@ trait ScalaSettings extends AbsScalaSettings
self: MutableSettings =>
/** Set of settings */
- protected lazy val allSettings = mutable.HashSet[Setting]()
+ protected[scala] lazy val allSettings = mutable.HashSet[Setting]()
/** Against my better judgment, giving in to martin here and allowing
* CLASSPATH to be used automatically. So for the user-specified part
diff --git a/test/junit/scala/tools/nsc/settings/SettingsTest.scala b/test/junit/scala/tools/nsc/settings/SettingsTest.scala
new file mode 100644
index 0000000000..4b0e58ff79
--- /dev/null
+++ b/test/junit/scala/tools/nsc/settings/SettingsTest.scala
@@ -0,0 +1,28 @@
+package scala.tools.nsc
+package settings
+
+import org.junit.Assert._
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import scala.tools.testing.AssertUtil.assertThrows
+
+@RunWith(classOf[JUnit4])
+class SettingsTest {
+ @Test def booleanSettingColon() {
+ def check(args: String*): MutableSettings#BooleanSetting = {
+ val s = new MutableSettings(msg => throw new IllegalArgumentException(msg))
+ val b1 = new s.BooleanSetting("-Ytest-setting", "")
+ s.allSettings += b1
+ val (ok, residual) = s.processArguments(args.toList, processAll = true)
+ assert(residual.isEmpty)
+ b1
+ }
+ assertTrue(check("-Ytest-setting").value)
+ assertTrue(check("-Ytest-setting:true").value)
+ assertTrue(check("-Ytest-setting:TRUE").value)
+ assertFalse(check("-Ytest-setting:false").value)
+ assertFalse(check("-Ytest-setting:FALSE").value)
+ assertThrows[IllegalArgumentException](check("-Ytest-setting:rubbish"))
+ }
+}