Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 98b22a767 -> f38d48d87


GROOVY-7940: @Lazy not generating "is" property accessor for booleans (closes 
#420)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: f38d48d87a0d7a9167fd7585ffb415a9517103cc
Parents: 98b22a7
Author: John Wagenleitner <jwagenleit...@apache.org>
Authored: Sat Sep 17 21:22:53 2016 -0700
Committer: John Wagenleitner <jwagenleit...@apache.org>
Committed: Sat Sep 17 21:25:42 2016 -0700

----------------------------------------------------------------------
 .../groovy/transform/LazyASTTransformation.java   |  9 +++++++--
 .../groovy/transform/LazyTransformTest.groovy     | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f38d48d8/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 3aa6a9e..eb6642f 100644
--- a/src/main/org/codehaus/groovy/transform/LazyASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/LazyASTTransformation.java
@@ -43,6 +43,7 @@ import static 
org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.assignS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.assignX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.block;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.callThisX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX;
@@ -158,8 +159,12 @@ public class LazyASTTransformation extends 
AbstractASTTransformation {
     private static void addMethod(FieldNode fieldNode, BlockStatement body, 
ClassNode type) {
         int visibility = ACC_PUBLIC;
         if (fieldNode.isStatic()) visibility |= ACC_STATIC;
-        final String name = "get" + 
MetaClassHelper.capitalize(fieldNode.getName().substring(1));
-        fieldNode.getDeclaringClass().addMethod(name, visibility, type, 
Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body);
+        String propName = 
MetaClassHelper.capitalize(fieldNode.getName().substring(1));
+        fieldNode.getDeclaringClass().addMethod("get" + propName, visibility, 
type, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body);
+        if (ClassHelper.boolean_TYPE.equals(type)) {
+            fieldNode.getDeclaringClass().addMethod("is" + propName, 
visibility, type,
+                    Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, 
stmt(callThisX("get" + propName)));
+        }
     }
 
     private static void createSoft(FieldNode fieldNode, Expression initExpr) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/f38d48d8/src/test/org/codehaus/groovy/transform/LazyTransformTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/transform/LazyTransformTest.groovy 
b/src/test/org/codehaus/groovy/transform/LazyTransformTest.groovy
index fe729b7..60b019f 100644
--- a/src/test/org/codehaus/groovy/transform/LazyTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/LazyTransformTest.groovy
@@ -188,4 +188,22 @@ class LazyTransformTest extends GroovyShellTestCase {
         """)
         assertEquals([10,20,30,40,50,60], res)
     }
+
+    // GROOVY-7940
+    void testGeneratesIsAndGetAccessorsForBooleanPrimitives() {
+        assertScript '''
+            class Super {
+                boolean aBoolean = true
+            }
+
+            class Testing extends Super {
+                @Lazy
+                boolean aBoolean = {-> false }()
+            }
+
+            assert !new Testing().isaBoolean()
+            assert !new Testing().getaBoolean()
+            assert !new Testing().aBoolean
+        '''
+    }
 }

Reply via email to