You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/05/09 14:29:00 UTC
[jira] [Commented] (GROOVY-10549) Allow records to generate getter methods
[ https://issues.apache.org/jira/browse/GROOVY-10549?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17720951#comment-17720951 ]
Eric Milles commented on GROOVY-10549:
--------------------------------------
This is the bit where the typical property behavior is altered to accommodate {{record}} semantics: https://github.com/apache/groovy/blob/34e1858423b8e4041c39f677942d436a35fdfae4/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java#L492
Is your goal to have both forms of the property accessor or just the bean-style ones?
{code:groovy}
record Person(String firstName, String lastName) {
// String getFirstName()
// String getLastName()
// String firstName() ?
// String lastName() ?
}
{code}
If you want to experiment with this, you can change the getter names back like this:
{code:groovy}
@groovy.transform.ASTTest({
node.getProperties().each { pn ->
pn.setGetterName('get' + org.apache.groovy.util.BeanUtils.capitalize(pn.getName()))
}
})
record Person(String firstName, String lastName) {
}
{code}
> Allow records to generate getter methods
> ----------------------------------------
>
> Key: GROOVY-10549
> URL: https://issues.apache.org/jira/browse/GROOVY-10549
> Project: Groovy
> Issue Type: Improvement
> Components: record
> Affects Versions: 4.0.1
> Reporter: Christopher Smith
> Priority: Major
>
> Records are very cool. However, the decision to drop the traditional JavaBeans prefixes means that _lots_ of infrastructure is incompatible until major libraries update to a baseline that includes record features. (For the moment, this includes the Groovy compiler...)
> For compatibility purposes, it would be convenient to still generate the traditional getFoo methods on records. This might not be preferable as a default, so perhaps it's a {{RecordOptions.getter}} setting?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)