Groovy - AST Transformations Case Study

AST Transformations implemented in Groovy. What is a practical example of using AST transformation?

+4
source share
3 answers

This page contains practical use cases: @Singleton, @Lazy, @Immutable, @Delegate, @Newify, @Category, @Mixin, @PackageScope

+4
source

Scenarios like:

  • Authorization Check - Security, checking role from context
  • Print Values ​​of parameters with which the method is called
  • Statements Parameters are not null or not checked
  • Check various input conditions / method prerequisites
  • Generic Style AOP StyleMode ()
  • Create a method and mark it to run as runnable or main method.

Take a look at my AST AOP blog post and AST Param is not null

Hope this helps!

+3
source

Most practical examples of using AST transforms are given on this page. I often used @Delegate to delegate to another class or @Lazy for lazy loading. @Grab is great for pulling dependencies from the Maven / ivy repository. All are based on AST transformations and are part of the core language.

You can use the transforms directly, but most of the material you want is already built. You can do what you might want to do with AOP in other languages.

0
source

Source: https://habr.com/ru/post/1300350/


All Articles