stats
是语句的缩写,而 children 就是它的意思。我运行了这两种方法,结果似乎相同。有人可以向我指出两者之间的更详细区别。
附上示例代码,请随时在 Scastie 上运行它(https://scastie.scala-lang.org/A6huYabOTGmpZu9HRa6UZw)
val program = """
object Main {
def main(args: Array[String]): Unit = {
println("Hello Scalameta!")
}
def cats(args: Array[String]): Unit = {
println("Ancient cat here!")
}
def bats(args: Array[String]): Unit = {
println("Ancient bat here!")
}
def dragons = {
bats(List())
cats(List())
}
val ancient = dragons()
}
"""
import scala.meta._
val tree = program.parse[Source].get
println(tree.stats.head.children)
println("-----------------------\n")
tree.children.head.children.tail.head.children.foreach(child => {
println(s"${child.productPrefix} From: ${child.pos.startLine} and End: ${child.pos.endLine}")
println(child)
println("-----------------------\n")
})