-
Notifications
You must be signed in to change notification settings - Fork 8
/
DemoPlugin.scala
35 lines (27 loc) · 1.04 KB
/
DemoPlugin.scala
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
package demo
import scala.tools.nsc.{ Global, Phase }
import scala.tools.nsc.plugins.{ Plugin, PluginComponent }
class DemoPlugin(val global: Global) extends Plugin {
val name = "demo-plugin"
val description = "Enforces coding standards"
val components = List[PluginComponent](DemoComponent)
private object DemoComponent extends PluginComponent {
val global = DemoPlugin.this.global
import global._
override val runsAfter = List("erasure")
val phaseName = "Demo"
override def newPhase(prev: Phase): StdPhase = new StdPhase(prev) {
override def apply(unit: CompilationUnit) {
new DemoTraverser(unit) traverse unit.body
}
}
class DemoTraverser(unit: CompilationUnit) extends Traverser {
override def traverse(tree: Tree): Unit = tree match {
case New(tpt) if exitingTyper(tpt.tpe.typeSymbol.isDerivedValueClass) =>
reporter.warning(tree.pos, s"Value class `${tpt.tpe.typeSymbol.fullName}` instantiated!")
case _ =>
super.traverse(tree)
}
}
}
}