This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new ff9c8d0  GROOVY-8969: Parameter name data is erased when applying 
traits regardless of --parameters setting
ff9c8d0 is described below

commit ff9c8d0378ab28757d8d9a1edf6854776665080f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Jan 27 14:42:38 2019 +1000

    GROOVY-8969: Parameter name data is erased when applying traits regardless 
of --parameters setting
---
 .../groovy/transform/trait/TraitComposer.java      |  2 +-
 .../test/groovy/groovy/ant/Groovy8969Test.groovy   | 66 ++++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java 
b/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java
index e85fe4d..fd39152 100644
--- a/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java
+++ b/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java
@@ -154,7 +154,7 @@ public abstract class TraitComposer {
                     Parameter parameter = helperMethodParams[i];
                     ClassNode originType = parameter.getOriginType();
                     ClassNode fixedType = 
correctToGenericsSpecRecurse(methodGenericsSpec, originType);
-                    Parameter newParam = new Parameter(fixedType, "arg" + i);
+                    Parameter newParam = new Parameter(fixedType, 
parameter.getName());
                     List<AnnotationNode> copied = new 
LinkedList<AnnotationNode>();
                     List<AnnotationNode> notCopied = new 
LinkedList<AnnotationNode>();
                     GeneralUtils.copyAnnotatedNodeAnnotations(parameter, 
copied, notCopied);
diff --git 
a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8969Test.groovy 
b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8969Test.groovy
new file mode 100644
index 0000000..cdadb16
--- /dev/null
+++ b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8969Test.groovy
@@ -0,0 +1,66 @@
+/*
+ *  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 Groovy8969Test extends AntTestCase {
+    private scriptParamNameCheck = '''
+        import org.codehaus.groovy.control.CompilerConfiguration
+        def cc = new CompilerConfiguration(parameters: true)
+        def shell = new GroovyShell(getClass().classLoader, cc)
+        shell.evaluate """
+            trait HasUpper {
+                def upper(String upperParam) { upperParam.toUpperCase() }
+            }
+
+            class Main implements HasLower, HasUpper { }
+
+            assert Main.getMethod('lower', String).parameters[0].name == 
'lowerParam'
+            assert Main.getMethod('upper', String).parameters[0].name == 
'upperParam'
+
+            assert new Main().with{ lower('Foo') + upper('Bar') } == 'fooBAR'
+        """
+    '''
+
+    void testParameterNamesSeenInAST() {
+        if (System.getProperty('java.specification.version') < '1.8') return
+//        def debugLogger = new org.apache.tools.ant.DefaultLogger()
+//        debugLogger.setMessageOutputLevel(4)
+//        debugLogger.setOutputPrintStream(System.out)
+//        debugLogger.setErrorPrintStream(System.err)
+
+        doInTmpDir { ant, baseDir ->
+            println baseDir
+            baseDir.src {
+                'HasLower.groovy'('''
+                    trait HasLower {
+                        def lower(String lowerParam) { 
lowerParam.toLowerCase() }
+                    }
+                ''')
+            }
+//            ant.project.addBuildListener(debugLogger)
+            ant.mkdir(dir: 'build')
+            ant.taskdef(name: 'groovyc', classname: 
'org.codehaus.groovy.ant.Groovyc')
+            ant.groovyc(srcdir: 'src', destdir: 'build', parameters: 'true')
+            ant.taskdef(name: 'groovy', classname: 
'org.codehaus.groovy.ant.Groovy')
+            ant.groovy(scriptParamNameCheck) {
+                classpath { pathelement(path: 'build') }
+            }
+        }
+    }
+}

Reply via email to