Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X f38d48d87 -> 0afacb4d3


GROOVY-7942: @Lazy transform creates unneeded getter/setter for backing store 
field (closes #423)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 0afacb4d3df1cac267035ec4ada28f70cbaa2d55
Parents: f38d48d
Author: paulk <pa...@asert.com.au>
Authored: Sun Sep 18 10:17:24 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Sun Sep 18 18:38:27 2016 +1000

----------------------------------------------------------------------
 src/main/groovy/lang/Lazy.java                  |  3 --
 .../groovy/transform/LazyASTTransformation.java |  8 ++++-
 src/test/groovy/bugs/Groovy3726Bug.groovy       | 34 ++++----------------
 3 files changed, 13 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/0afacb4d/src/main/groovy/lang/Lazy.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/Lazy.java b/src/main/groovy/lang/Lazy.java
index 9a1e3b9..c715bc0 100644
--- a/src/main/groovy/lang/Lazy.java
+++ b/src/main/groovy/lang/Lazy.java
@@ -143,9 +143,6 @@ import java.lang.annotation.Target;
  *     return DateHolder_date3.INSTANCE
  * }
  * </pre>
- *
- * @author Alex Tkachman
- * @author Paul King
  */
 @java.lang.annotation.Documented
 @Retention(RetentionPolicy.SOURCE)

http://git-wip-us.apache.org/repos/asf/groovy/blob/0afacb4d/src/main/org/codehaus/groovy/transform/LazyASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/LazyASTTransformation.java 
b/src/main/org/codehaus/groovy/transform/LazyASTTransformation.java
index eb6642f..a8eb6d4 100644
--- a/src/main/org/codehaus/groovy/transform/LazyASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/LazyASTTransformation.java
@@ -26,6 +26,7 @@ import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.FieldNode;
 import org.codehaus.groovy.ast.InnerClassNode;
 import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.PropertyNode;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.MethodCallExpression;
@@ -84,8 +85,13 @@ public class LazyASTTransformation extends 
AbstractASTTransformation {
         final Expression soft = node.getMember("soft");
         final Expression init = getInitExpr(fieldNode);
 
-        fieldNode.rename("$" + fieldNode.getName());
+        String backingFieldName = "$" + fieldNode.getName();
+        fieldNode.rename(backingFieldName);
         fieldNode.setModifiers(ACC_PRIVATE | (fieldNode.getModifiers() & 
(~(ACC_PUBLIC | ACC_PROTECTED))));
+        PropertyNode pNode = 
fieldNode.getDeclaringClass().getProperty(backingFieldName);
+        if (pNode != null) {
+            fieldNode.getDeclaringClass().getProperties().remove(pNode);
+        }
 
         if (soft instanceof ConstantExpression && ((ConstantExpression) 
soft).getValue().equals(true)) {
             createSoft(fieldNode, init);

http://git-wip-us.apache.org/repos/asf/groovy/blob/0afacb4d/src/test/groovy/bugs/Groovy3726Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy3726Bug.groovy 
b/src/test/groovy/bugs/Groovy3726Bug.groovy
index 79e2c5b..2fa8cea 100644
--- a/src/test/groovy/bugs/Groovy3726Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3726Bug.groovy
@@ -24,29 +24,18 @@ class Groovy3726Bug extends GroovyTestCase {
     void testVolatilePropertiesResultingInBridgeMethods() {
         def scriptStr, clazz, fooGetter, fooSetter
         GroovyClassLoader cl = new GroovyClassLoader();
-        
-        scriptStr = """
-            public class GroovyBean3726A {
-                @Lazy volatile String foo = "anything"
-            }
-        """
-        clazz = cl.parseClass(scriptStr, 'GroovyBean3726A.groovy')
-        
-        fooGetter = clazz.getMethod('get$foo')
-        assertFalse fooGetter.isBridge()
-        assertFalse Modifier.isVolatile(fooGetter.modifiers)
-        
+
         scriptStr = """
             public class GroovyBean3726B {
                 volatile String foo = "anything"
             }
         """
         clazz = cl.parseClass(scriptStr, 'GroovyBean3726B.groovy')
-        
+
         fooGetter = clazz.getMethod('getFoo')
         assertFalse fooGetter.isBridge()
         assertFalse Modifier.isVolatile(fooGetter.modifiers)
-        
+
         fooSetter = clazz.getMethod('setFoo', [String] as Class[])
         assertFalse fooSetter.isBridge()
         assertFalse Modifier.isVolatile(fooSetter.modifiers)
@@ -55,29 +44,18 @@ class Groovy3726Bug extends GroovyTestCase {
     void testTransientPropertiesResultingInVarArgsMethods() {
         def scriptStr, clazz, barGetter, barSetter
         GroovyClassLoader cl = new GroovyClassLoader();
-        
-        scriptStr = """
-            public class GroovyBean3726C {
-                @Lazy transient String bar = "anything"
-            }
-        """
-        clazz = cl.parseClass(scriptStr, 'GroovyBean3726C.groovy')
-        
-        barGetter = clazz.getMethod('get$bar')
-        assertFalse barGetter.isVarArgs()
-        assertFalse Modifier.isTransient(barGetter.modifiers)
-        
+
         scriptStr = """
             public class GroovyBean3726D {
                 transient String bar = "anything"
             }
         """
         clazz = cl.parseClass(scriptStr, 'GroovyBean3726D.groovy')
-        
+
         barGetter = clazz.getMethod('getBar')
         assertFalse barGetter.isVarArgs()
         assertFalse Modifier.isTransient(barGetter.modifiers)
-        
+
         barSetter = clazz.getMethod('setBar', [String] as Class[])
         assertFalse barSetter.isVarArgs()
         assertFalse Modifier.isTransient(barSetter.modifiers)

Reply via email to