Metaprogramming With The Groovy Compiler - Part 2 of 2
summary
Shows how Groovy compile-time metaprogramming uses AST transformations to mutate classes: a magicNumber annotation triggers an AST transform that injects a public method so getMagicNumber returns 42 in the generated .class file, the unit test passes, and Java can call the added method. Demonstrates Grails examples (allowedMethods moved from runtime to compile time, controller actions wrapped with try/catch, domain classes gaining static count), and notes standard transforms like singleton and immutable that modify bytecode at compile time.
AI-written summary · about
chapters (15)
- 0:00Introduction to talk
- 1:46Compile-time metaprogramming overview
- 8:10Grails compile-time transformations
- 14:36AST transformations explained
- 19:56Building a magic number AST
- 29:04Testing the AST transformation
- 31:14AST transformation limitations
- 35:07Bytecode impact and Java interop
- 36:10Grails domain class ASTs
- 38:16Controller action AST modifications
- 41:49AST vs AOP comparison
- 44:05Global vs local AST transformations
- 46:33Grails framework ASTs
- 48:19Built-in Groovy AST transformations
- 50:48Takeaways and conclusion
related talks
51mThe Craft of Metaprogramming on JVM
50mRevealing the magic behind Java annotations
42mEternal Sunshine of the Spotless Macro
45mMaking Java more dynamic
46mJava annotation processing magic for muggles
40mJoy of Meta-Tracing Just-in-Time Compilation: More Than Just a VM Generator
39mBytecode Transformations: Exploring new AGP APIs for instrumenting your app
44mMetaprogramming 2.0
