concept tree in category groovy

appears as: tree, The tree, trees
Groovy in Action, Second Edition

This is an excerpt from Manning's book Groovy in Action, Second Edition.

The Visitor pattern is particularly useful when you wish to perform complex business functionality on a composite collection (such as a tree or list) of existing simple classes. Rather than altering the existing simple classes to contain the desired business functionality, a Visitor class is introduced. Visitor knows how to traverse the composite collection and how to perform the business functionality for different kinds of a simple class. If the composite changes or the business functionality changes over time, typically only the Visitor class is impacted.

The examples in chapter 9 are focused on writing new information into the AST of a class. Transformations give you the class and method nodes you need to work with as parameters. This is enough when you want to write AST. But things aren’t always so simple. Often, we need to read the AST to discover more information about it, such as which statements are next to each other, or which variables are in scope. To answer more complex questions about the AST content you will need to walk the tree.