concept hand in category groovy

This is an excerpt from Manning's book Groovy in Action, Second Edition.
Let’s take a closer look at what makes Groovy so appealing, starting with how Groovy and Java work hand-in-hand.
Don’t be too concerned about the details in this equivalent code listing. After our tour of Groovy’s built-in transformations, you’ll get to see more details about such generated code. Most of the code should look similar to what you might write by hand, but for the curious, we’ll point out that there are some calls of InvokerHelper utility methods that you can safely ignore if you haven’t come across them before. They ensure that the property values printed will be correct even if dynamic changes have been made, and these values will be output using Groovy’s standard formatting mechanisms.
The lack of abstraction can be seen in the example. For example, a ConstructorCallExpression accepts a ClassNode and an Expression as arguments (they’re used as the constructor type and arguments). To write this AST by hand you need to know that an empty argument list is ArgumentListExpression.EMPTY_ARGUMENTS and not null. Also, you need to know that the best type to use for the constructor arguments is an ArgumentListExpression object. You can use other types but they probably aren’t what you intend. Lastly and most importantly, a ClassNode should be made by calling the ClassHelper.make() method.
Listing 11.19. By-hand calorie builder
class CalorieBuilder3 { def calorieDatabase = [ crust : [thin: 169, classic: 212, deepdish: 259, stuffed: 360], topping : [pepperoni: 24, veggies: 10, cheese: 50], appetizer: [wings: 60, 'garlic-bread': 180] ] def parent = new Stack() def getCalories() { parent.peek().calories } CalorieBuilder3() { parent.push([calories:0.0]) } def invokeMethod(String methodName, args) { def current = [name: methodName, calories:0.0] if (args && args[0] instanceof Map) { current << args[0] } countCalories(current, parent.peek().name, methodName) if (args && args[0] instanceof String) { countCalories(current, methodName, args[0]) } if (args && args.size() > 1 && args[1] instanceof String) { countCalories(current, methodName, args[1]) } current.scale = current.size == 'large' ? 1.5 : 1.0 if (args && args[-1] instanceof Closure) { parent.push(current) Closure nested = args[-1] nested.delegate = this nested.call() parent.pop() } def qty = current.quantity ?: 1 def scale = current.scale ?: 1.0 parent.peek().calories += current.calories * qty * scale } private void countCalories(Map current, String key, String value) { if (calorieDatabase.containsKey(key)) { current.calories = calorieDatabase[key][value].toInteger() } } } def lunch = new CalorieBuilder3() lunch.count { pizza(size: 'large') { crust('thin') topping('pepperoni') topping('veggies') } appetizer { wings(quantity: 2) 'garlic-bread'() } } assert lunch.calories == 604.5