forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomGlobal.scala
33 lines (28 loc) · 1.02 KB
/
CustomGlobal.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
package custom
import scala.tools.nsc._, reporters._, typechecker._
/** Demonstration of a custom Global with a custom Typer,
* decoupled from trunk. Demonstration:
*
{{{
scalac -d . CustomGlobal.scala && scala -nc -Yglobal-class custom.CustomGlobal \
-e 'class Bippy(x: Int) ; def f = new Bippy(5)'
I'm typing a Bippy! It's a ClassDef.
I'm typing a Bippy! It's a Ident.
I'm typing a Bippy! It's a DefDef.
}}}
*
*/
class CustomGlobal(currentSettings: Settings, reporter: Reporter) extends Global(currentSettings, reporter) {
override lazy val analyzer = new {
val global: CustomGlobal.this.type = CustomGlobal.this
} with Analyzer {
override def newTyper(context: Context): Typer = new CustomTyper(context)
class CustomTyper(context : Context) extends Typer(context) {
override def typed(tree: Tree, mode: Int, pt: Type): Tree = {
if (tree.summaryString contains "Bippy")
println("I'm typing a Bippy! It's a " + tree.shortClass + ".")
super.typed(tree, mode, pt)
}
}
}
}