Metaprogramming and DSLs
Five lessons on the part of Groovy that a build script uses without naming it: a class that answers a call it never declared, a method added at run time, the transforms the compiler applies, the builders that write XML and JSON, and a DSL of your own with a delegate and @DelegatesTo.
7.1
methodMissing and propertyMissing
a class that answers a call it does not declare, and the error it throws for a typo
Open
7.2
ExpandoMetaClass and categories
adding a method to a class at run time, and the category class that scopes it
Open
7.3
AST transformations in use
the transforms the language ships, and a local one written with @AnnotationCollector
Open
7.4
Builders
MarkupBuilder and JsonBuilder, and the tree a builder builds
Open
7.5
A small DSL
a builder of your own with a delegate, and @DelegatesTo for the type checker
Open