summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/plugins/Plugin.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-07-25 19:52:15 -0700
committerSom Snytt <som.snytt@gmail.com>2013-08-21 17:03:03 -0700
commitf3731f9ace5d3d5e213ea786fe0027ea66c5358b (patch)
treefb068e41ba1e2aabf0cff642e1d3b47590ef4d12 /src/compiler/scala/tools/nsc/plugins/Plugin.scala
parent79d619127bb84ef858476252ace53b730d2e38cd (diff)
downloadscala-f3731f9ace5d3d5e213ea786fe0027ea66c5358b.tar.gz
scala-f3731f9ace5d3d5e213ea786fe0027ea66c5358b.tar.bz2
scala-f3731f9ace5d3d5e213ea786fe0027ea66c5358b.zip
SI-7622 Plugins can be not enabled
Plugins can interrogate options and declare themselves not enabled. The plugin itself can return false from its init if the options do not compute. A plugin phase component can declare itself not enabled, same as an internal phase. No one exploits this facility at this commit.
Diffstat (limited to 'src/compiler/scala/tools/nsc/plugins/Plugin.scala')
-rw-r--r--src/compiler/scala/tools/nsc/plugins/Plugin.scala29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/plugins/Plugin.scala b/src/compiler/scala/tools/nsc/plugins/Plugin.scala
index 4fd6ba7d9d..1578caff26 100644
--- a/src/compiler/scala/tools/nsc/plugins/Plugin.scala
+++ b/src/compiler/scala/tools/nsc/plugins/Plugin.scala
@@ -41,12 +41,31 @@ abstract class Plugin {
*/
val global: Global
- /** Handle any plugin-specific options. The `-P:plugname:` part
- * will not be present.
+ def options: List[String] = {
+ // Process plugin options of form plugin:option
+ def namec = name + ":"
+ global.settings.pluginOptions.value filter (_ startsWith namec) map (_ stripPrefix namec)
+ }
+
+ /** Handle any plugin-specific options.
+ * The user writes `-P:plugname:opt1,opt2`,
+ * but the plugin sees `List(opt1, opt2)`.
+ * The plugin can opt out of further processing
+ * by returning false. For example, if the plugin
+ * has an "enable" flag, now would be a good time
+ * to sit on the bench.
+ * @param options plugin arguments
+ * @param error error function
+ * @return true to continue, or false to opt out
*/
- def processOptions(options: List[String], error: String => Unit) {
- if (!options.isEmpty)
- error("Error: " + name + " has no options")
+ def init(options: List[String], error: String => Unit): Boolean = {
+ processOptions(options, error)
+ true
+ }
+
+ @deprecated("use Plugin#init instead", since="2.11")
+ def processOptions(options: List[String], error: String => Unit): Unit = {
+ if (!options.isEmpty) error(s"Error: $name takes no options")
}
/** A description of this plugin's options, suitable as a response