summaryrefslogtreecommitdiff
path: root/docs/examples/plugintemplate/src/plugintemplate/TemplateTraverseComponent.scala
blob: 400daf74378da19f489792b64005c4d08bf16272 (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
package plugintemplate

import scala.tools.nsc._
import scala.tools.nsc.plugins.PluginComponent

/** This class implements a plugin component using a tree
 *  traverser */
class TemplateTraverseComponent (val global: Global) extends PluginComponent {
  import global._
  import global.definitions._

  val runsAfter = List[String]("refchecks")
  /** The phase name of the compiler plugin
   *  @todo Adapt to specific plugin.
   */
  val phaseName = "plugintemplatetraverse"

  def newPhase(prev: Phase): Phase = new TraverserPhase(prev)
  class TraverserPhase(prev: Phase) extends StdPhase(prev) {
    def apply(unit: CompilationUnit) {
      newTraverser().traverse(unit.body)
    }
  }

  def newTraverser(): Traverser = new ForeachTreeTraverser(check)

  def check(tree: Tree): Unit = tree match {
    case Apply(fun, args) =>
      println("traversing application of "+ fun)
    case _ => ()
  }
}