The main focus of this blog post wasn’t to describe in details how the AST transformation works, but rather show you how a smart combination of the features of Groovy 2.1 can allow you to perform tasks that would seem impossible, like type checking at compile-time the usage of a builder, statically compiling the code and eventually, performing checks on things that are normally unchecked by the compiler (arguments of a call).
In the end, this example is not complete, of course:
-
the definition of the schema is insufficient (what about tags that allow arbitrary tags, …)
-
allowText attribute isn’t used yet
-
the error messages can be improved (yes, it is possible to replace them with tags!)
-
the API can be improved for more fluency
But what is more important is that using such techniques, I am pretty sure that someone even crazier than me could write a more complete implementation that would accept, say… a real schema (think of xsd)!