Java Magazine, Mar/Apr 2018
Figure 2 AST tree for the code in Figure 1 ORACLE COM JAVAMAGAZINE MARCH APRIL 2018 68 jvm languages The source code for the transformation class which can be found on Github shows the details of the transformation and is far too long to include here The source consists of more than 200 lines that work with instances of classes such as VariableExpression MethodCallExpression FieldNode PropertyNode BlockStatement and so on which combine to generate the tree shown in Figure 2 The beauty of the new macro approach is that much of the code in the transformation class can be rewritten as normal Groovy statements wrapped in a block called macro The Groovy language documentation shows a trivial example where AST transformation code such as ReturnStatement code new ReturnStatement new ConstantExpression 42 can be replaced with ReturnStatement simplestCode macro return 42
You must have JavaScript enabled to view digital editions.