Listing the properties of a class in order
In the same vein as my recent article on how to know the variables which are bound or not in a script, a user asked how he could list in order the properties defined in a class. Unfortunately, using MyClass.metaClass.properties won’t guarantee the order in which properties were created. But reusing the technique in my previous article, one can visit the Groovy AST, in order, and just look at the property definitions, fill an ordered list of these properties, and return it once the traversal is finished. Here’s what I came up with:
Read more...