groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [2/2] groovy git commit: GROOVY-8627: Compile error using NamedParam with value
Date Tue, 19 Jun 2018 06:08:07 GMT
GROOVY-8627: Compile error using NamedParam with value


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 8da611c4930d3df01590a567369961c3a9297f47
Parents: a13ec54
Author: Paul King <paulk@asert.com.au>
Authored: Sat Jun 16 13:52:21 2018 +1000
Committer: Paul King <paulk@asert.com.au>
Committed: Tue Jun 19 16:07:54 2018 +1000

----------------------------------------------------------------------
 src/main/groovy/groovy/transform/NamedParam.java  |  2 +-
 .../transform/NamedVariantASTTransformation.java  |  2 +-
 .../transform/NamedVariantTransformTest.groovy    | 18 ++++++++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/8da611c4/src/main/groovy/groovy/transform/NamedParam.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/transform/NamedParam.java b/src/main/groovy/groovy/transform/NamedParam.java
index 78d98d8..24ac75b 100644
--- a/src/main/groovy/groovy/transform/NamedParam.java
+++ b/src/main/groovy/groovy/transform/NamedParam.java
@@ -33,7 +33,7 @@ import java.lang.annotation.Target;
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.PARAMETER)
 public @interface NamedParam {
-    String value();
+    String value() default Undefined.STRING;
     Class type() default Object.class;
     boolean required() default false;
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/8da611c4/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
index 64e2b32..b5e85e7 100644
--- a/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
@@ -113,7 +113,7 @@ public class NamedVariantASTTransformation extends AbstractASTTransformation
{
                 if (AnnotatedNodeUtils.hasAnnotation(fromParam, NAMED_PARAM_TYPE)) {
                     AnnotationNode namedParam = fromParam.getAnnotations(NAMED_PARAM_TYPE).get(0);
                     boolean required = memberHasValue(namedParam, "required", true);
-                    if (getMemberValue(namedParam, "name") == null) {
+                    if (getMemberStringValue(namedParam, "value") == null) {
                         namedParam.addMember("value", constX(fromParam.getName()));
                     }
                     String name = getMemberStringValue(namedParam, "value");

http://git-wip-us.apache.org/repos/asf/groovy/blob/8da611c4/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy b/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy
index db15bab..48fff3d 100644
--- a/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy
@@ -49,6 +49,24 @@ class NamedVariantTransformTest extends GroovyShellTestCase {
         '''
     }
 
+    void testNamedParamWithRename() {
+        assertScript '''
+            import groovy.transform.*
+
+            @ToString(includeNames=true)
+            class Color {
+                Integer r, g, b
+            }
+
+            @NamedVariant
+            String m(@NamedDelegate Color color, @NamedParam('a') int alpha) {
+                return [color, alpha].join(' ')
+            }
+
+            assert m(r:1, g:2, b:3, a: 0) == 'Color(r:1, g:2, b:3) 0'
+        '''
+    }
+
     void testNamedParamConstructor() {
         assertScript """
             import groovy.transform.*


Mime
View raw message