[3/3] groovy git commit: GROOVY-8872: Populate the parameter names from the byte code when available (convert test artifact from list to map)

2018-11-10 Thread paulk
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/eb3494ef
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/eb3494ef
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/eb3494ef

Branch: refs/heads/GROOVY_2_5_X
Commit: eb3494ef73b795288f42efc628771703e5085ca5
Parents: 66c8707
Author: Paul King 
Authored: Sat Nov 10 20:10:30 2018 +1000
Committer: Paul King 
Committed: Sat Nov 10 20:41:09 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/eb3494ef/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 f0b20e0..d9abc76 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;
@@ -649,6 +651,14 @@ public class GeneralUtils {
 return new BinaryExpression(lhv, LT, rhv);
 }
 
+public static MapExpression mapX(List expressions) {
+return new MapExpression(expressions);
+}
+
+public static MapEntryExpression entryX(Expression key, Expression value) {
+return new MapEntryExpression(key, value);
+}
+
 /**
  * @deprecated use 
MethodNodeUtils#methodDescriptorWithoutReturnType(MethodNode) instead
  */

http://git-wip-us.apache.org/repos/asf/groovy/blob/eb3494ef/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 

groovy git commit: GROOVY-8872: Populate the parameter names from the byte code when available (convert test artifact from list to map)

2018-11-10 Thread paulk
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 
Authored: Sat Nov 10 20:10:30 2018 +1000
Committer: Paul King 
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 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),