groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: GROOVY-8367: @Memoized not working for inner classes (closes #624)
Date Wed, 01 Nov 2017 09:28:37 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X b45e36aac -> 05074bf1e


GROOVY-8367: @Memoized not working for inner classes (closes #624)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 05074bf1eb75fbc7d3c368857f6da4aec950e5f3
Parents: b45e36a
Author: paulk <paulk@asert.com.au>
Authored: Mon Oct 30 21:42:53 2017 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Wed Nov 1 19:28:24 2017 +1000

----------------------------------------------------------------------
 .../transform/MemoizedASTTransformation.java       |  4 +---
 .../transform/MemoizedASTTransformationTest.groovy | 17 +++++++++++++++--
 2 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/05074bf1/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 0360e46..c20c075 100644
--- a/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
@@ -54,8 +54,6 @@ import static org.codehaus.groovy.ast.tools.GenericsUtils.newClass;
 
 /**
  * Handles generation of code for the {@link Memoized} annotation.
- *
- * @author Andrey Bloschetsov
  */
 @GroovyASTTransformation(phase = CompilePhase.SEMANTIC_ANALYSIS)
 public class MemoizedASTTransformation extends AbstractASTTransformation {
@@ -110,7 +108,7 @@ public class MemoizedASTTransformation extends AbstractASTTransformation
{
             closureCallExpression.setImplicitThis(false);
             newCode.addStatement(returnS(closureCallExpression));
             methodNode.setCode(newCode);
-            VariableScopeVisitor visitor = new VariableScopeVisitor(source);
+            VariableScopeVisitor visitor = new VariableScopeVisitor(source, ownerClassNode
instanceof InnerClassNode);
             if (ownerClassNode instanceof InnerClassNode) {
                 visitor.visitClass(((InnerClassNode) ownerClassNode).getOuterMostClass());
             } else {

http://git-wip-us.apache.org/repos/asf/groovy/blob/05074bf1/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 f55ac12..242617d 100644
--- a/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
@@ -25,8 +25,6 @@ import static org.junit.Assert.*
 
 /**
  * Unit tests for {@link MemoizedASTTransformation}.
- *
- * @author Andrey Bloschetsov
  */
 class MemoizedASTTransformationTest extends GroovyTestCase {
 
@@ -219,6 +217,21 @@ class MemoizedASTTransformationTest extends GroovyTestCase {
             assert new A().toString() == 'an expensive toString operation'
         '''
     }
+
+    // GROOVY-8367
+    void testMemoizedInInnerClass() {
+        assertScript '''
+            import groovy.transform.Memoized
+            class Outer {
+                private static int count = 0
+                private static class Inner {
+                    @Memoized
+                    static calc(int arg1, int arg2) { count++; arg1 + arg2 }
+                }
+            }
+            assert Outer.Inner.calc(3, 4) + Outer.Inner.calc(3, 4) + Outer.count == 15
+        '''
+    }
 }
 
 class MemoizedTestClass2 {


Mime
View raw message