groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [1/2] groovy git commit: GROOVY-8637: @NamedVariant processing error
Date Tue, 19 Jun 2018 06:08:06 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X a13ec5468 -> ccd1873e6


GROOVY-8637: @NamedVariant processing error


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

Branch: refs/heads/GROOVY_2_5_X
Commit: ccd1873e601426afe7f575ef52d551fc99b23020
Parents: 8da611c
Author: Paul King <paulk@asert.com.au>
Authored: Sat Jun 16 12:34:00 2018 +1000
Committer: Paul King <paulk@asert.com.au>
Committed: Tue Jun 19 16:07:54 2018 +1000

----------------------------------------------------------------------
 .../java/org/codehaus/groovy/ast/tools/BeanUtils.java  |  3 +++
 .../groovy/transform/NamedVariantTransformTest.groovy  | 13 +++++++++++++
 2 files changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/ccd1873e/src/main/java/org/codehaus/groovy/ast/tools/BeanUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/BeanUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/BeanUtils.java
index ab266c2..28c2270 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/BeanUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/BeanUtils.java
@@ -18,6 +18,7 @@
  */
 package org.codehaus.groovy.ast.tools;
 
+import groovy.transform.Generated;
 import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.MethodNode;
@@ -35,6 +36,7 @@ public class BeanUtils {
     static final String GET_PREFIX = "get";
     static final String SET_PREFIX = "set";
     static final String IS_PREFIX = "is";
+    private static final ClassNode GENERATED_TYPE = ClassHelper.make(Generated.class);
 
     /**
      * Get all properties including JavaBean pseudo properties matching getter conventions.
@@ -97,6 +99,7 @@ public class BeanUtils {
         List<MethodNode> methods = cNode.getAllDeclaredMethods();
         for (MethodNode mNode : methods) {
             if (!includeStatic && mNode.isStatic()) continue;
+            if (mNode.getAnnotations(GENERATED_TYPE).size() > 0) continue;
             String name = mNode.getName();
             if ((name.length() <= 3 && !name.startsWith(IS_PREFIX)) || name.equals("getClass")
|| name.equals("getMetaClass") || name.equals("getDeclaringClass")) {
                 // Optimization: skip invalid propertyNames

http://git-wip-us.apache.org/repos/asf/groovy/blob/ccd1873e/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 48fff3d..4e5077f 100644
--- a/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy
@@ -143,4 +143,17 @@ class NamedVariantTransformTest extends GroovyShellTestCase {
         '''
     }
 
+    void testGeneratedMethodsSkipped() {
+        assertScript '''
+            import groovy.transform.*
+            import static org.codehaus.groovy.transform.NamedVariantTransformTest.*
+
+            @NamedVariant
+            def baz(@NamedDelegate Storm st, @NamedDelegate Switch sw) { st.front + sw.back
}
+            assert baz(front: 'Hello', back: 'World') == 'HelloWorld'
+        '''
+    }
+
+    static class Storm { String front }
+    static class Switch { String back }
 }


Mime
View raw message