Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
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


Re: knowing the get/set method names of an attribute [message #645342 is a reply to message #645335] Thu, 16 December 2010 16:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
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 #645364 is a reply to message #645342] Thu, 16 December 2010 18:28 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 12/16/2010 05:58 PM, Ed Merks wrote:
>> 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 Ed!

I'll first take a look at the templates and if the algorithm is simple
I'll try to re-implement in plain Java code; I'll also take a look at
the GenModel though :)

cheers
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


Re: knowing the get/set method names of an attribute [message #645365 is a reply to message #645357] Thu, 16 December 2010 18:29 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
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


Re: knowing the get/set method names of an attribute [message #645548 is a reply to message #645365] Fri, 17 December 2010 19:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
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


Re: knowing the get/set method names of an attribute [message #645669 is a reply to message #645635] Sun, 19 December 2010 17:07 Go to previous message
Ed Merks is currently offline Ed MerksFriend
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/
Previous Topic:Customization of XML serialization
Next Topic:EMF Interim Update Site Broken
Goto Forum:
  


Current Time: Sat Apr 27 03:34:58 GMT 2024

Powered by FUDForum. Page generated in 0.04224 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top