You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/11/10 10:10:39 UTC
groovy git commit: GROOVY-8872: Populate the parameter names from the
byte code when available (convert test artifact from list to map)
Repository: groovy
Updated Branches:
refs/heads/master 2193eaf8c -> a905ba470
GROOVY-8872: Populate the parameter names from the byte code when available (convert test artifact from list to map)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a905ba47
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a905ba47
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a905ba47
Branch: refs/heads/master
Commit: a905ba470ec7505b206a086fc1d6c42bbfb95ae1
Parents: 2193eaf
Author: Paul King <pa...@asert.com.au>
Authored: Sat Nov 10 20:10:30 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Sat Nov 10 20:10:30 2018 +1000
----------------------------------------------------------------------
.../codehaus/groovy/ast/tools/GeneralUtils.java | 10 ++++++++++
.../test/groovy/groovy/ant/Groovy8872Test.groovy | 19 +++++++++----------
2 files changed, 19 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/a905ba47/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
index 06755ee..ed985cc 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
@@ -43,6 +43,8 @@ import org.codehaus.groovy.ast.expr.DeclarationExpression;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.expr.FieldExpression;
import org.codehaus.groovy.ast.expr.ListExpression;
+import org.codehaus.groovy.ast.expr.MapEntryExpression;
+import org.codehaus.groovy.ast.expr.MapExpression;
import org.codehaus.groovy.ast.expr.MethodCallExpression;
import org.codehaus.groovy.ast.expr.NotExpression;
import org.codehaus.groovy.ast.expr.PropertyExpression;
@@ -652,6 +654,14 @@ public class GeneralUtils {
return new BinaryExpression(lhv, LT, rhv);
}
+ public static MapExpression mapX(List<MapEntryExpression> expressions) {
+ return new MapExpression(expressions);
+ }
+
+ public static MapEntryExpression entryX(Expression key, Expression value) {
+ return new MapEntryExpression(key, value);
+ }
+
public static BinaryExpression notIdenticalX(Expression lhv, Expression rhv) {
return new BinaryExpression(lhv, NOT_IDENTICAL, rhv);
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/a905ba47/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy
index e43714a..7e5db65 100644
--- a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy
+++ b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy
@@ -23,11 +23,8 @@ class Groovy8872Test extends AntTestCase {
@ExtractParamNames
abstract class DummyClass implements JavaInterface, GroovyInterface {}
- def paramNames = DummyClass.paramNames
- assert paramNames == [
- ['name', 'dob', 'vip'],
- ['id', 'eventName', 'dateOfEvent']
- ]
+ assert DummyClass.paramNames.addPerson == ['name', 'dob', 'vip']
+ assert DummyClass.paramNames.addEvent == ['id', 'eventName', 'dateOfEvent']
'''
void testParameterNamesSeenInAST() {
@@ -55,8 +52,8 @@ class Groovy8872Test extends AntTestCase {
import java.lang.annotation.*
/**
- * Test transform adds a static method to a class that returns a map from the name
- * for each found method to its parameter names.
+ * Test transform adds a static field to a class that returns a map
+ * from the name for each found method to its parameter names.
*/
@java.lang.annotation.Documented
@Retention(RetentionPolicy.SOURCE)
@@ -78,9 +75,11 @@ class Groovy8872Test extends AntTestCase {
init(nodes, source)
def classNode = nodes[1]
assert classNode instanceof ClassNode
- def result = listX(classNode.abstractMethods.collect{ list2args(it.parameters.name) })
- classNode.addField(new FieldNode("paramNames", ACC_PUBLIC+ACC_STATIC+ACC_FINAL,
- ClassHelper.LIST_TYPE.plainNodeReference, classNode, result))
+ def result = mapX(classNode.allDeclaredMethods.collect{
+ entryX(constX(it.name), list2args(it.parameters.name))
+ })
+ classNode.addField(new FieldNode("paramNames", ACC_PUBLIC + ACC_STATIC + ACC_FINAL,
+ ClassHelper.MAP_TYPE.plainNodeReference, classNode, result))
}
}
''')