summaryrefslogtreecommitdiff
path: root/docs/examples/plugintemplate/src/plugintemplate/TemplatePlugin.scala
blob: 6cda37d4e3b120c7810c4da859c9117a511ac231 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package plugintemplate

import scala.tools.nsc.Global
import scala.tools.nsc.plugins.Plugin

/** A class describing the compiler plugin
 *
 *  @todo Adapt the name of this class to the plugin being
 *  implemented
 */
class TemplatePlugin(val global: Global) extends Plugin {
  /** The name of this plugin. Extracted from the properties file. */
  val name = PluginProperties.pluginName

  val runsAfter = List[String]("refchecks")

  /** A short description of the plugin, read from the properties file */
  val description = PluginProperties.pluginDescription
  
  /** @todo A description of the plugin's options */
  override val optionsHelp = Some(
    "  -P:"+ name +":option     sets some option for this plugin")

  /** @todo Implement parsing of plugin options */
  override def processOptions(options: List[String], error: String => Unit) {
    super.processOptions(options, error)
  }

  /** The compiler components that will be applied when running
   *  this plugin
   *
   *  @todo Adapt to the plugin being implemented
   */
  val components = TemplatePlugin.components(global)

  val checker = new TemplateAnnotationChecker {
    val global: TemplatePlugin.this.global.type = TemplatePlugin.this.global
  }
  global.addAnnotationChecker(checker.checker)
}

object TemplatePlugin {
  /** Yields the list of Components to be executed in this plugin
   *
   *  @todo: Adapt to specific implementation.
   */
  def components(global: Global) =
    List(new TemplateComponent(global),
         new TemplateTraverseComponent(global),
         new TemplateTransformComponent(global),
         new TemplateInfoTransformComponent(global))
}