使用-Xprint:typer
(在 typer 之后转储树)和-Yshow-trees-compact
(以原始 AST 格式转储树)。如果您还使用-Yshow-trees-stringified
,则 AST 将另外转储为伪 Scala 代码(注意:最后两个选项需要 2.10.0)。
C:\Projects\Kepler\sandbox @ ticket/6356>cat Test.scala
class C {
def x = 2
}
C:\Projects\Kepler\sandbox @ ticket/6356>scalac -Xprint:typer -Yshow-trees-compact -Yshow-trees-stringified Test.scala
[[syntax trees at end of typer]]// Scala source: Test.scala
package <empty> {
class C extends scala.AnyRef {
def <init>(): C = {
C.super.<init>();
()
};
def x: Int = 2
}
}
PackageDef(
Ident(<empty>),
List(
ClassDef(Modifiers(), newTypeName("C"), List(),
Template(List(Select(Ident(scala), newTypeName("AnyRef"))), emptyValDef,
List(
DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(newTypeName("C")), tpnme.EMPTY), nme.CONSTRUCTOR), List())), Literal(Constant(())))),
DefDef(Modifiers(), newTermName("x"), List(), List(), TypeTree(), Literal(Constant(2))))))))