Why use a TreeNode instead of a normal AST visitor?

7 views
Skip to first unread message

Hamlet D'Arcy

unread,
Jan 17, 2011, 7:24:06 AM1/17/11
to GroovyLint
Hi,

Just checking out the source code which I found in the .zip file I
downloaded. Trying to estimate what it would take to adapt GroovyLint
rules into CodeNarc rules :)

It looks like GroovyLint's NodeBuildingVisitor class uses a
GroovyCodeVisitor to build a org.groovylint.TreeNode object.

What is the advantage of building this TreeNode instead of just
performing the work directly in a CodeVisitorSupport instance? Is it
because an ASTNode tree is a mixture of different types and you want
to have a standard tree walking algorithm? Or what?

Thanks,

Kyle

unread,
Jan 17, 2011, 11:02:24 AM1/17/11
to GroovyLint
Yea, I just wanted a collection so I could use standard Groovy
collection methods (grep, collect, etc). Also TreeNode let's me know
what the parent of each node is.

Hamlet D'Arcy

unread,
Jan 20, 2011, 7:30:09 AM1/20/11
to GroovyLint
> Yea, I just wanted a collection so I could use standard Groovy
> collection methods (grep, collect, etc).

That's an interesting idea. I like that. However, in general I am
worried about adding new access methods to the ASTNode class heirarchy
because it is already a large, complex tree of inheritance. Still,
having these collection functions work on ASTNodes is a good idea.

> Also TreeNode let's me know
> what the parent of each node is.

FYI, in 1.8 you can store arbitrary metadata on any ASTNode, so adding
"getParent/setParent" functionality is easy.
Reply all
Reply to author
Forward
0 new messages