O'Reilly logo

Programming Groovy 2 by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Intercepting Method Calls Using AST Transformations

Imagine we’re in the middle of developing some banking software and the businesspeople throw a curveball at us. They want every $10K-plus deposit, withdrawal, or transfer involving a checking account to be audited. We want to respond to this request quickly, so let’s consider some options.

Our least favorable option would have us hunt for all places we perform a transaction on any checking account. Even with our favorite high-octane integrated development environment, finding and modifying the calls would not be fun. Furthermore, each time we call one of the methods, we would have to remember to perform the audit operation.

Another option is to modify the methods of the checking-account class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required