groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Keegan Witt <keeganw...@gmail.com>
Subject Re: Groovy doesn't follow java beans specification on certain edge cases?
Date Mon, 01 Jun 2015 15:18:01 GMT
Section 8.8 of the spec
<http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/>
is
unclear on the proper capitalization in cases like you've described.
However, if you examine the java.beans.Introspector.decapitalize(String
name) source
<http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/java/beans/Introspector.java>,
you'll find that Groovy follows the convention as implemented in the
JDK (my guess is Groovy probably calls that exact method somewhere).  As
such, I believe Groovy's behavior is correct as-implemented.

-Keegan

On Fri, May 29, 2015 at 10:17 AM, Miro Bezjak <bezjak.miro@gmail.com> wrote:

> If by property name you mean: field name (not relevant in this case) +
> getter name + setter name, then yes.
>
> That is, for `cName`, groovy generates: `getcName` and `setcName`. But it
> should (probably?) generate: `getCName` and `setCName`.
>
> Regards,
> Miro
>
> On Fri, May 29, 2015 at 3:39 PM, Jochen Theodorou <blackdrag@gmx.org>
> wrote:
>
>> Am 29.05.2015 15:32, schrieb Miro Bezjak:
>> [...]
>>
>>> As far as I can see, this only affects java.beans. The following example
>>> works without any problem:
>>> --------------------------------------
>>> class Foo {
>>>      String cName
>>> }
>>>
>>> def f = new Foo()
>>> f.cName = 'abc'
>>> println f.cName // abc
>>> --------------------------------------
>>>
>>>
>>> One workaround is to define proper getter and setter:
>>> --------------------------------------
>>> class Foo {
>>>      String cName
>>>
>>>      String getCName() { cName }
>>>      void setCName(String cName) { this.cName = cName }
>>> }
>>>
>>> new java.beans.PropertyDescriptor('cName', Foo) // ok now
>>> --------------------------------------
>>>
>>
>> that would mean the isCName method missing is a false flag and really
>> this is about capitalization of property names
>>
>> bye blackdrag
>>
>> --
>> Jochen "blackdrag" Theodorou
>> blog: http://blackdragsview.blogspot.com/
>>
>>
>

Mime
View raw message