0

stats is short for statements while children is what it's. I ran both methods and it seems results are same. Can someone please point to me a more detailed differentiation between both.

Attaching a sample code, feel free to run it on 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")
})
Ravinder Payal
  • 2,884
  • 31
  • 40

1 Answers1

0

Every Tree has children: List[Tree] but only Source (and its inheritors) has stats: List[Stat].

https://www.javadoc.io/doc/org.scalameta/trees_2.13/latest/scala/meta/Tree.html

https://www.javadoc.io/doc/org.scalameta/trees_2.13/latest/scala/meta/Source.html

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66