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

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

Github user shils commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/187#discussion_r44695586
  
    --- Diff: 
src/test/org/codehaus/groovy/transform/TupleConstructorTransformTest.groovy ---
    @@ -131,10 +131,37 @@ class TupleConstructorTransformTest extends 
GroovyShellTestCase {
     
                 assert new Cat("Felix").toString() == 'Cat(name:Felix)'
                 assert new Cat("Felix", 42).toString() == 'Cat(name:Felix, 
id:42)'
    -            //assert new Cat("Felix", 42, 3.5d).toString() == 
'Cat(age:3.5, name:Felix, id:42)'
    +            assert new Cat("Felix", 42, 3.5d).toString() == 'Cat(age:3.5, 
name:Felix, id:42)'
                 assert new Cat(3.5d).toString() == 'Cat(age:3.5)'
                 assert new Cat().toString() == 'Cat()'
             '''
         }
     
    +    void testMultipleUsages_groovy7672() {
    +        assertScript '''
    +            import groovy.transform.*
    +            import java.awt.Color
    +
    +            class Named {
    +                String name
    +            }
    +
    +            @ToString(includeSuperProperties=true, ignoreNulls=true, 
includeNames=true, includeFields=true)
    +            @TupleConstructor(force=true, defaults=false)
    +            @TupleConstructor(force=true, defaults=false, 
includeFields=true)
    --- End diff --
    
    I think it would be helpful to include a multiple usage example like this 
in the documentation.


> TupleConstructor should have only SOURCE retention policy
> ---------------------------------------------------------
>
>                 Key: GROOVY-7672
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7672
>             Project: Groovy
>          Issue Type: Improvement
>    Affects Versions: 2.4.5
>            Reporter: Paul King
>            Assignee: Paul King
>
> We originally gave TupleConstructor RUNTIME retention policy since it might 
> provide a small amount of introspection information for future tools. But so 
> far, as far as I know, it hasn't been used. Given that it makes certain 
> usages impossible, I propose to put back to SOURCE retention policy. This 
> will allow code such as shown below to be possible:
> {code}
> import groovy.transform.*
> import java.awt.Color
> class Named {
>     String name
> }
> @ToString(includeSuperProperties=true, ignoreNulls=true, includeNames=true, 
> includeFields=true)
> @TupleConstructor(force=true, defaults=false)
> @TupleConstructor(force=true, defaults=false, includeFields=true)
> @TupleConstructor(force=true, defaults=false, includeSuperProperties=true)
> class Cat extends Named {
>     int age
>     private Color color
> }
> assert new Cat("Felix", 3).toString() == 'Cat(age:3, name:Felix)'
> assert new Cat(3, Color.BLACK).toString() == 'Cat(age:3, 
> color:java.awt.Color[r=0,g=0,b=0])'
> assert new Cat(3).toString() == 'Cat(age:3)'
> {code}



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

Reply via email to