Repository: groovy
Updated Branches:
  refs/heads/master 998f12314 -> 40d878f12


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/40d878f1
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/40d878f1
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/40d878f1

Branch: refs/heads/master
Commit: 40d878f1278a3a1e90dfd519eff56ed6f1ab18db
Parents: 998f123
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:35:34 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/40d878f1/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/40d878f1/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 480654b..37c0028 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.EmptyExpression;
 import org.codehaus.groovy.ast.expr.Expression;
@@ -82,8 +83,13 @@ public class LazyASTTransformation extends 
AbstractASTTransformation {
         final Expression soft = node.getMember("soft");
         final Expression init = getInitExpr(xform, 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/40d878f1/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