groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7940) Inconsistent handling of undocumented primitive data types at the @Lazy annotation under use of extends
Date Sat, 17 Sep 2016 21:27:20 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7940?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15499719#comment-15499719
] 

ASF GitHub Bot commented on GROOVY-7940:
----------------------------------------

Github user paulk-asert commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/420#discussion_r79292382
  
    --- Diff: src/main/org/codehaus/groovy/transform/LazyASTTransformation.java ---
    @@ -156,8 +156,11 @@ private static void addNonThreadSafeBody(BlockStatement body, FieldNode
fieldNod
         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, body);
    --- End diff --
    
    I'd probably use 'stmt(callThisX("get" + propName))' instead of 'body'. That should give
a slightly smaller class.


> Inconsistent handling of undocumented primitive data types at the @Lazy annotation under
use of extends
> -------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7940
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7940
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 2.4.5
>         Environment: Any
>            Reporter: Maik Igloffstein
>              Labels: data, extends, lazy, primitives, super, types
>
> *Documentation:* http://docs.groovy-lang.org/latest/html/gapi/groovy/lang/Lazy.html
> The documentations describes the usage of _@Lazy_ like:
> {{@Lazy T x}}
> I'm aware of that _T_ means no primitive data types, but groovy allows it and generates
the code - so why not.
> {code}
> class Super {
>     boolean aBoolean = true
>     int aInt = 5
> }
> class Testing extends Super {
>     @Lazy
>     boolean aBoolean = { false }()
>     
>     @Lazy
>     int aInt = { 5 * 5 }()
> }
> println new Testing().isaBoolean()
> println new Testing().getaBoolean()
> println new Testing().getaInt()
> println new Testing().aBoolean
> println new Testing().aInt
> {code}
> Result:
> {code}
> true
> false
> 25
> true
> 25
> {code}
> The behavior is inconsistent.
> boolean: results are from the super class
> int: results are from the child class
> -Please fix it or throw a _'RuntimeException'_ when primitive data types are used.-
> *Update:*
> Please let _@Lazy_ implement \_is\_Boolean() instead of \_get\_Boolean() when using primitive
data type boolean and document it or just throw a _'RuntimeException'_.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message