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


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

Branch: refs/heads/master
Commit: 998f123144404bce45ba5206d214d9aca0250e3f
Parents: f5a161f
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:22:53 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/998f1231/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 871fe70..480654b 100644
--- a/src/main/org/codehaus/groovy/transform/LazyASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/LazyASTTransformation.java
@@ -44,6 +44,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;
@@ -156,8 +157,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/998f1231/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 de8b110..8d292d9 100644
--- a/src/test/org/codehaus/groovy/transform/LazyTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/LazyTransformTest.groovy
@@ -202,4 +202,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