I understand that it is possible to obtain a Tree corresponding to a Scala expression, and also to traverse the resulting tree. Suppose that a given tree node matches some criterion, what method calls do I need to be able to modify it in place?, i.e. replace it with some other 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)
}
}
In another question I was suggested to use Transformer to do something similar. AFAIK it is not possible to modify the tree in place, however.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With