我知道可以获取与 Scala 表达式对应的 Tree,也可以遍历生成的树。假设一个给定的树节点匹配某个标准,我需要什么方法调用才能修改它?即用其他树替换它?
object traverser extends Traverser {
var applies = List[Apply]()
override def traverse(tree: Tree): Unit = tree match {
case someCriterion => modifyNodeSomehow // How to do this?
// Otherwise...
case app @ Apply(fun, args) =>
applies = app :: applies
super.traverse(fun)
super.traverseTrees(args)
case _ => super.traverse(tree)
}
}