Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.0
-
None
-
None
Description
Following my article found here: http://www.jroller.com/melix/entry/improved_ast_transformation_testing_in
It would be nice to have a label lookup feature, which would allow to write, for example:
@ASTTest(phase=INSTRUCTION_SELECTION, value= { lookup('forLoop').each { assert it instanceof org.codehaus.groovy.ast.stmt.ForStatement def collection = it.collectionExpression // MethodCallExpression def inft = collection.getNodeMetaData(INFERRED_TYPE) assert inft == make(Set) def entryInft = inft.genericsTypes[0].type assert entryInft == make(Map.Entry) assert entryInft.genericsTypes[0].type == STRING_TYPE assert entryInft.genericsTypes[1].type == Integer_TYPE } }) void test() { def result = "" def sum = 0 forLoop: for ( Map.Entry<String, Integer> it in [a:1, b:3].entrySet() ) { result += it.getKey() sum += it.getValue() } assert result == "ab" assert sum == 4 } test()
The idea is that looking for a label is a smarter way of finding AST nodes than hardcoding a path.