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-8326: @Override should not copied onto methods generated by applying @Memoize (closes #610)
Date Sun, 01 Oct 2017 21:06:11 GMT
GROOVY-8326: @Override should not copied onto methods generated by applying @Memoize (closes
#610)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: f3b2b8f6267f8ea832ad9bb6488bc872aaec9002
Parents: f5332a8
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Sat Sep 30 21:06:49 2017 -0700
Committer: paulk <paulk@asert.com.au>
Committed: Mon Oct 2 07:05:53 2017 +1000

----------------------------------------------------------------------
 .../groovy/transform/MemoizedASTTransformation.java   | 14 ++++++++++++--
 .../transform/MemoizedASTTransformationTest.groovy    | 14 ++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f3b2b8f6/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java b/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
index 2769a33..0360e46 100644
--- a/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
@@ -68,6 +68,7 @@ public class MemoizedASTTransformation extends AbstractASTTransformation
{
     private static final String MAX_CACHE_SIZE_NAME = "maxCacheSize";
     private static final String CLOSURE_LABEL = "Closure";
     private static final String METHOD_LABEL = "Priv";
+    private static final ClassNode OVERRIDE_CLASSNODE = make(Override.class);
 
     public void visit(ASTNode[] nodes, final SourceUnit source) {
         init(nodes, source);
@@ -132,11 +133,20 @@ public class MemoizedASTTransformation extends AbstractASTTransformation
{
                 annotatedMethod.getExceptions(),
                 code
         );
-        List<AnnotationNode> sourceAnnotations = annotatedMethod.getAnnotations();
-        method.addAnnotations(new ArrayList<AnnotationNode>(sourceAnnotations));
+        method.addAnnotations(filterAnnotations(annotatedMethod.getAnnotations()));
         return method;
     }
 
+    private static List<AnnotationNode> filterAnnotations(List<AnnotationNode>
annotations) {
+        List<AnnotationNode> result = new ArrayList<AnnotationNode>(annotations.size());
+        for (AnnotationNode annotation : annotations) {
+            if (!OVERRIDE_CLASSNODE.equals(annotation.getClassNode())) {
+                result.add(annotation);
+            }
+        }
+        return result;
+    }
+
     private static final String MEMOIZE_METHOD_NAME = "memoize";
     private static final String MEMOIZE_AT_MOST_METHOD_NAME = "memoizeAtMost";
     private static final String MEMOIZE_AT_LEAST_METHOD_NAME = "memoizeAtLeast";

http://git-wip-us.apache.org/repos/asf/groovy/blob/f3b2b8f6/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy b/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
index 77e3f61..f55ac12 100644
--- a/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
@@ -205,6 +205,20 @@ class MemoizedASTTransformationTest extends GroovyTestCase {
             }.a() == 'a'
         '''
     }
+
+    // GROOVY-8326
+    void testMemoizedMethodWithOverrideAnnotation() {
+        assertScript '''
+            class A {            
+                @groovy.transform.Memoized
+                @Override
+                String toString() {
+                    'an expensive toString operation'
+                }
+            }
+            assert new A().toString() == 'an expensive toString operation'
+        '''
+    }
 }
 
 class MemoizedTestClass2 {


Mime
View raw message