You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/05/02 02:04:14 UTC
[jira] [Closed] (GROOVY-7394) @ToString could support non-field
properties
[ https://issues.apache.org/jira/browse/GROOVY-7394?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-7394.
-----------------------------
> @ToString could support non-field properties
> --------------------------------------------
>
> Key: GROOVY-7394
> URL: https://issues.apache.org/jira/browse/GROOVY-7394
> Project: Groovy
> Issue Type: Bug
> Components: xforms
> Affects Versions: 2.4.3
> Reporter: Christopher Smith
> Assignee: Paul King
> Priority: Minor
> Labels: breaking
> Fix For: 2.5.0-alpha-1
>
>
> Cloned from the @EqualsAndHashCode issue to handle the same problem with @ToString as an independent issue.
> I have the following class representing a location in Amazon S3. Depending on some inner business logic, I often need to split the object key into a prefix and a file name, so I access them all through the {{getKey()}} method; with S3, the only thing that matters is the final concatenated string.
> The generated {{toString}} method doesn't display properties following the JavaBean conventions, e.g. with explicit getXxx() or isYyy() methods but no field as per normal Groovy conventions for properties with auto getters/setters.
> {code}
> import groovy.transform.*
> @ToString(includes = ['bucket', 'key'], includeNames = true)
> class S3ImageLocation {
> final String bucket
> final String prefix
> final String subKey
> S3ImageLocation(String bucket, String prefix, String subKey) {
> this.bucket = bucket
> this.prefix = prefix
> this.subKey = subKey
> }
> S3ImageLocation(String bucket, String subKey) {
> this(bucket, null, subKey)
> }
> String getKey() { prefix ? "$prefix/$subKey" : subKey }
> }
> // expected below (current is 'S3ImageLocation(bucket:foo)')
> assert new S3ImageLocation('foo', 'bar', 'baz').toString() == 'S3ImageLocation(bucket:foo, key:bar/baz)'
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)