Home » Modeling » EMF » knowing the get/set method names of an attribute
knowing the get/set method names of an attribute [message #645335] |
Thu, 16 December 2010 16:22 |
|
Hi
say that I have an attribute in a class, say foo, the generated get and
set names are
getFoo/setFoo
however, I guess I cannot simply assume that the pattern is
"get" + s.substring(0, 1).toUpperCase() + s.substring(1);
if s is the attribute name, since in cases where the corresponding
get/set method name clashes with a same name of the java library the
generated code takes care about that
for instance, if the attribute is "class" the get method will not be
getClass()
which would clash with the java library getClass(), but
getClass_()
so I was wondering what is the algorithm for getting the get method
name, if I have an attribute? Is it accessible via some util method?
thanks in advance
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: knowing the get/set method names of an attribute [message #645342 is a reply to message #645335] |
Thu, 16 December 2010 16:58 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Lorenzo,
Comments below.
Lorenzo Bettini wrote:
> Hi
>
> say that I have an attribute in a class, say foo, the generated get
> and set names are
>
> getFoo/setFoo
>
> however, I guess I cannot simply assume that the pattern is
>
> "get" + s.substring(0, 1).toUpperCase() + s.substring(1);
Not in general, no.
>
> if s is the attribute name, since in cases where the corresponding
> get/set method name clashes with a same name of the java library the
> generated code takes care about that
>
> for instance, if the attribute is "class" the get method will not be
>
> getClass()
>
> which would clash with the java library getClass(), but
>
> getClass_()
Exactly.
>
> so I was wondering what is the algorithm for getting the get method
> name, if I have an attribute? Is it accessible via some util method?
All such things are handled by the GenModel. Looking at the templates
you can pretty much figure it out. Things like getGetAccessor do the
work...
If you want to generate code that properly maps onto what EMF is
generating, you really should be reusing the GenModel...
>
> thanks in advance
> Lorenzo
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: knowing the get/set method names of an attribute [message #645357 is a reply to message #645335] |
Thu, 16 December 2010 17:39 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
What are you trying to solve? Do you want to call this using reflection?
- in this case you use eGet/eSet.
Tom
Am 16.12.10 17:22, schrieb Lorenzo Bettini:
> Hi
>
> say that I have an attribute in a class, say foo, the generated get and
> set names are
>
> getFoo/setFoo
>
> however, I guess I cannot simply assume that the pattern is
>
> "get" + s.substring(0, 1).toUpperCase() + s.substring(1);
>
> if s is the attribute name, since in cases where the corresponding
> get/set method name clashes with a same name of the java library the
> generated code takes care about that
>
> for instance, if the attribute is "class" the get method will not be
>
> getClass()
>
> which would clash with the java library getClass(), but
>
> getClass_()
>
> so I was wondering what is the algorithm for getting the get method
> name, if I have an attribute? Is it accessible via some util method?
>
> thanks in advance
> Lorenzo
>
|
|
| |
Re: knowing the get/set method names of an attribute [message #645365 is a reply to message #645357] |
Thu, 16 December 2010 18:29 |
|
mhh... using reflection I'd lose static type checking, wouldn't I?
My goal is to generate Java code from a DSL where I access attributes of
EMF classes and objects...
thanks
Lore
On 12/16/2010 06:39 PM, Tom Schindl wrote:
> What are you trying to solve? Do you want to call this using reflection?
> - in this case you use eGet/eSet.
>
> Tom
>
> Am 16.12.10 17:22, schrieb Lorenzo Bettini:
>> Hi
>>
>> say that I have an attribute in a class, say foo, the generated get and
>> set names are
>>
>> getFoo/setFoo
>>
>> however, I guess I cannot simply assume that the pattern is
>>
>> "get" + s.substring(0, 1).toUpperCase() + s.substring(1);
>>
>> if s is the attribute name, since in cases where the corresponding
>> get/set method name clashes with a same name of the java library the
>> generated code takes care about that
>>
>> for instance, if the attribute is "class" the get method will not be
>>
>> getClass()
>>
>> which would clash with the java library getClass(), but
>>
>> getClass_()
>>
>> so I was wondering what is the algorithm for getting the get method
>> name, if I have an attribute? Is it accessible via some util method?
>>
>> thanks in advance
>> Lorenzo
>>
>
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: knowing the get/set method names of an attribute [message #645548 is a reply to message #645365] |
Fri, 17 December 2010 19:37 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Lorenzo,
For generation purposes, you should use the GenModel. It provides
hundreds of conveniences and essentials...
Cheers,
Ed
Lorenzo Bettini wrote:
> mhh... using reflection I'd lose static type checking, wouldn't I?
>
> My goal is to generate Java code from a DSL where I access attributes
> of EMF classes and objects...
>
> thanks
> Lore
>
> On 12/16/2010 06:39 PM, Tom Schindl wrote:
>> What are you trying to solve? Do you want to call this using reflection?
>> - in this case you use eGet/eSet.
>>
>> Tom
>>
>> Am 16.12.10 17:22, schrieb Lorenzo Bettini:
>>> Hi
>>>
>>> say that I have an attribute in a class, say foo, the generated get and
>>> set names are
>>>
>>> getFoo/setFoo
>>>
>>> however, I guess I cannot simply assume that the pattern is
>>>
>>> "get" + s.substring(0, 1).toUpperCase() + s.substring(1);
>>>
>>> if s is the attribute name, since in cases where the corresponding
>>> get/set method name clashes with a same name of the java library the
>>> generated code takes care about that
>>>
>>> for instance, if the attribute is "class" the get method will not be
>>>
>>> getClass()
>>>
>>> which would clash with the java library getClass(), but
>>>
>>> getClass_()
>>>
>>> so I was wondering what is the algorithm for getting the get method
>>> name, if I have an attribute? Is it accessible via some util method?
>>>
>>> thanks in advance
>>> Lorenzo
>>>
>>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: knowing the get/set method names of an attribute [message #645635 is a reply to message #645548] |
Sun, 19 December 2010 08:52 |
|
OK, I will!
But is GenModel documented? Or is there any doc online or kind of
tutorial or example?
thanks in advance
Lore
On 12/17/2010 08:37 PM, Ed Merks wrote:
> Lorenzo,
>
> For generation purposes, you should use the GenModel. It provides
> hundreds of conveniences and essentials...
>
> Cheers,
> Ed
>
>
> Lorenzo Bettini wrote:
>> mhh... using reflection I'd lose static type checking, wouldn't I?
>>
>> My goal is to generate Java code from a DSL where I access attributes
>> of EMF classes and objects...
>>
>> thanks
>> Lore
>>
>> On 12/16/2010 06:39 PM, Tom Schindl wrote:
>>> What are you trying to solve? Do you want to call this using reflection?
>>> - in this case you use eGet/eSet.
>>>
>>> Tom
>>>
>>> Am 16.12.10 17:22, schrieb Lorenzo Bettini:
>>>> Hi
>>>>
>>>> say that I have an attribute in a class, say foo, the generated get and
>>>> set names are
>>>>
>>>> getFoo/setFoo
>>>>
>>>> however, I guess I cannot simply assume that the pattern is
>>>>
>>>> "get" + s.substring(0, 1).toUpperCase() + s.substring(1);
>>>>
>>>> if s is the attribute name, since in cases where the corresponding
>>>> get/set method name clashes with a same name of the java library the
>>>> generated code takes care about that
>>>>
>>>> for instance, if the attribute is "class" the get method will not be
>>>>
>>>> getClass()
>>>>
>>>> which would clash with the java library getClass(), but
>>>>
>>>> getClass_()
>>>>
>>>> so I was wondering what is the algorithm for getting the get method
>>>> name, if I have an attribute? Is it accessible via some util method?
>>>>
>>>> thanks in advance
>>>> Lorenzo
>>>>
>>>
>>
>>
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: knowing the get/set method names of an attribute [message #645669 is a reply to message #645635] |
Sun, 19 December 2010 17:07 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Lorenzo,
How it works is self evident from the names. :-P
Your best bet is generally to look at how it's used in EMF's various
templates. I.e., if you need to generate code that calls the generated
getter, look at what's used to generate the name of the getter in
Class.javajet.
Lorenzo Bettini wrote:
> OK, I will!
>
> But is GenModel documented? Or is there any doc online or kind of
> tutorial or example?
>
> thanks in advance
> Lore
>
> On 12/17/2010 08:37 PM, Ed Merks wrote:
>> Lorenzo,
>>
>> For generation purposes, you should use the GenModel. It provides
>> hundreds of conveniences and essentials...
>>
>> Cheers,
>> Ed
>>
>>
>> Lorenzo Bettini wrote:
>>> mhh... using reflection I'd lose static type checking, wouldn't I?
>>>
>>> My goal is to generate Java code from a DSL where I access attributes
>>> of EMF classes and objects...
>>>
>>> thanks
>>> Lore
>>>
>>> On 12/16/2010 06:39 PM, Tom Schindl wrote:
>>>> What are you trying to solve? Do you want to call this using
>>>> reflection?
>>>> - in this case you use eGet/eSet.
>>>>
>>>> Tom
>>>>
>>>> Am 16.12.10 17:22, schrieb Lorenzo Bettini:
>>>>> Hi
>>>>>
>>>>> say that I have an attribute in a class, say foo, the generated
>>>>> get and
>>>>> set names are
>>>>>
>>>>> getFoo/setFoo
>>>>>
>>>>> however, I guess I cannot simply assume that the pattern is
>>>>>
>>>>> "get" + s.substring(0, 1).toUpperCase() + s.substring(1);
>>>>>
>>>>> if s is the attribute name, since in cases where the corresponding
>>>>> get/set method name clashes with a same name of the java library the
>>>>> generated code takes care about that
>>>>>
>>>>> for instance, if the attribute is "class" the get method will not be
>>>>>
>>>>> getClass()
>>>>>
>>>>> which would clash with the java library getClass(), but
>>>>>
>>>>> getClass_()
>>>>>
>>>>> so I was wondering what is the algorithm for getting the get method
>>>>> name, if I have an attribute? Is it accessible via some util method?
>>>>>
>>>>> thanks in advance
>>>>> Lorenzo
>>>>>
>>>>
>>>
>>>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Sat Apr 27 03:34:58 GMT 2024
Powered by FUDForum. Page generated in 0.04224 seconds
|