Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 2ed7b2de8 -> eb3494ef7


GROOVY-8872: Populate the parameter names from the byte code when available 
(closes #820)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c8944a5b
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c8944a5b
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c8944a5b

Branch: refs/heads/GROOVY_2_5_X
Commit: c8944a5b9321df491b8feadd9c24324c6d79b406
Parents: 2ed7b2d
Author: jameskleeh <james.kl...@gmail.com>
Authored: Thu Nov 8 23:44:59 2018 -0500
Committer: Paul King <pa...@asert.com.au>
Committed: Sat Nov 10 20:39:47 2018 +1000

----------------------------------------------------------------------
 .../groovy/ast/decompiled/AsmDecompiler.java    |  6 ++
 .../groovy/ast/decompiled/ClassStub.java        |  1 +
 .../ast/decompiled/MemberSignatureParser.java   | 10 ++-
 .../groovy/groovy/ant/Groovy8872Test.groovy     | 88 ++++++++++++++++++++
 4 files changed, 104 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/c8944a5b/src/main/java/org/codehaus/groovy/ast/decompiled/AsmDecompiler.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/ast/decompiled/AsmDecompiler.java 
b/src/main/java/org/codehaus/groovy/ast/decompiled/AsmDecompiler.java
index 6286ff9..4e0f922 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/AsmDecompiler.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/AsmDecompiler.java
@@ -158,6 +158,12 @@ public abstract class AsmDecompiler {
                             }
                         };
                     }
+
+                    @Override
+                    public void visitParameter(String name, int access) {
+                        if (stub.parameterNames == null) stub.parameterNames = 
new ArrayList<String>();
+                        stub.parameterNames.add(name);
+                    }
                 };
             }
             return null;

http://git-wip-us.apache.org/repos/asf/groovy/blob/c8944a5b/src/main/java/org/codehaus/groovy/ast/decompiled/ClassStub.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/ClassStub.java 
b/src/main/java/org/codehaus/groovy/ast/decompiled/ClassStub.java
index 43b10df..96df728 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/ClassStub.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/ClassStub.java
@@ -65,6 +65,7 @@ class MethodStub extends MemberStub {
     final String signature;
     final String[] exceptions;
     Map<Integer, List<AnnotationStub>> parameterAnnotations;
+    List<String> parameterNames;
     Object annotationDefault;
 
     public MethodStub(String methodName, int accessModifiers, String desc, 
String signature, String[] exceptions) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/c8944a5b/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java 
b/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
index ecb1028..436c02c 100644
--- 
a/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
+++ 
b/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
@@ -97,8 +97,16 @@ class MemberSignatureParser {
         }
 
         Parameter[] parameters = new Parameter[parameterTypes.length];
+        List<String> parameterNames = method.parameterNames;
         for (int i = 0; i < parameterTypes.length; i++) {
-            parameters[i] = new Parameter(parameterTypes[i], "param" + i);
+            String parameterName = "param" + i;
+            if (parameterNames != null && i < parameterNames.size()) {
+                String decompiledName = parameterNames.get(i);
+                if (decompiledName != null) {
+                    parameterName = decompiledName;
+                }
+            }
+            parameters[i] = new Parameter(parameterTypes[i], parameterName);
         }
 
         if (method.parameterAnnotations != null) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/c8944a5b/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
new file mode 100644
index 0000000..1cd46e7
--- /dev/null
+++ b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.ant
+
+class Groovy8669Test extends AntTestCase {
+    private scriptAllOnPath = '''
+    def anno = AnnotatedClass.annotations[0]
+    def type = anno.annotationType()
+    assert type.name == 'MyAnnotation'
+    assert type.getDeclaredMethod('value').invoke(anno).name == 'ValueClass'
+    '''
+
+    private scriptNoValueClass = '''
+    // using annotations will cause ValueClass not to be found
+    // but should still be able to use the class otherwise
+    assert AnnotatedClass.name.size() == 14
+    '''
+
+    private scriptNoAnnotationOnPath = '''
+    // class should be usable but won't have annotations
+    assert !AnnotatedClass.annotations
+    '''
+
+    void testCreateZip() {
+//        def debugLogger = new org.apache.tools.ant.DefaultLogger()
+//        debugLogger.setMessageOutputLevel(4)
+//        debugLogger.setOutputPrintStream(System.out)
+//        debugLogger.setErrorPrintStream(System.err)
+
+        doInTmpDir { ant, baseDir ->
+            baseDir.src {
+                'ValueClass.java'('''
+                    public class ValueClass{ }
+                ''')
+                'MyAnnotation.java'('''
+                    import java.lang.annotation.*;
+
+                    @Target(ElementType.TYPE)
+                    @Retention(RetentionPolicy.RUNTIME)
+                    public @interface MyAnnotation {
+                        Class<ValueClass> value();
+                    }
+                ''')
+                'AnnotatedClass.java'('''
+                    @MyAnnotation(ValueClass.class)
+                    class AnnotatedClass { }
+                ''')
+            }
+//            ant.project.addBuildListener(debugLogger)
+            ant.mkdir(dir: 'build')
+            ant.javac(classpath: '.', destdir: 'build', srcdir: 'src',
+                    includes: '*.java', includeantruntime: 'false', fork: 
'true')
+            ['ValueClass', 'MyAnnotation', 'AnnotatedClass'].each { name ->
+                ant.mkdir(dir: "build$name")
+                ant.copy(file: "build/${name}.class", todir: "build$name")
+            }
+            ant.taskdef(name: 'groovy', classname: 
'org.codehaus.groovy.ant.Groovy')
+            ant.groovy(scriptAllOnPath) {
+                classpath { pathelement(path: 'buildValueClass') }
+                classpath { pathelement(path: 'buildMyAnnotation') }
+                classpath { pathelement(path: 'buildAnnotatedClass') }
+            }
+            ant.groovy(scriptNoValueClass) {
+                classpath { pathelement(path: 'buildMyAnnotation') }
+                classpath { pathelement(path: 'buildAnnotatedClass') }
+            }
+            ant.groovy(scriptNoAnnotationOnPath) {
+                classpath { pathelement(path: 'buildAnnotatedClass') }
+            }
+        }
+    }
+}

Reply via email to