Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Change getter/setter names
Change getter/setter names [message #653418] Wed, 09 February 2011 16:53 Go to next message
J.-P. Pellet is currently offline J.-P. PelletFriend
Messages: 71
Registered: July 2009
Member
Hi,

I'm experimenting with integrating EMF and Scala a bit more tightly. As
a first step, I'd like my generated code to have getters called
featureName(), and setters called featureName_$eq(...) for nicer Scala
interoperability.

(This has the effect that I can say "obj.featureName" to get it and
"obj.featureName = newValue" to set it in Scala.)

Is there a way to easily modify how the generator does this, or should I
rewrite my own complete generator?

(Eventually, I guess rewriting the whole generator in a Scala-idiomatic
way would be best, but I want to start simple.)

Cheers,
J.-P.
Re: Change getter/setter names [message #653512 is a reply to message #653418] Thu, 10 February 2011 03:54 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 09.02.2011 17:53, schrieb J.-P. Pellet:
> Hi,
>
> I'm experimenting with integrating EMF and Scala a bit more tightly. As a first step, I'd like my generated code to have getters called featureName(), and setters called featureName_$eq(...) for nicer Scala interoperability.
Personally I feel that an integration should be "a third thing", as non-invasive to the two things that are to be integrated. I would recommend that you investigate ways to use EMF reflection and introspection for your integration. But I know almost nothing about Scala and if that would be appropriate for Scala.

>
> (This has the effect that I can say "obj.featureName" to get it and "obj.featureName = newValue" to set it in Scala.)
>
> Is there a way to easily modify how the generator does this, or should I rewrite my own complete generator?
>
> (Eventually, I guess rewriting the whole generator in a Scala-idiomatic way would be best, but I want to start simple.)
Before you start to adjust or rewrite the actual JET templates I would investigate if you could customize the GenModel implementation. Things like the accessor names are computed in GenFeatureImpl.getGetAccessor(). I've never done that before and tere may be more dependencies you'd have to consider.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: Change getter/setter names [message #653585 is a reply to message #653512] Thu, 10 February 2011 10:26 Go to previous messageGo to next message
J.-P. Pellet is currently offline J.-P. PelletFriend
Messages: 71
Registered: July 2009
Member
> Before you start to adjust or rewrite the actual JET templates I would
> investigate if you could customize the GenModel implementation. Things
> like the accessor names are computed in GenFeatureImpl.getGetAccessor().
> I've never done that before and tere may be more dependencies you'd have
> to consider.

Yes, having my own custom subclass of GenModel is what I'm looking for.
I know there's a way to inject my own generators via extension points.
So is there a way to replace an existing generator with my own custom
subclass, for instance? Or to disable it depending on some property of
the generator model?

J.-P.
Re: Change getter/setter names [message #881978 is a reply to message #653585] Tue, 05 June 2012 15:12 Go to previous message
Filip Krikava is currently offline Filip KrikavaFriend
Messages: 45
Registered: January 2012
Member
Hi,

I see that it is an old thread, but anyway:

To get the getters is quite simple using a merged in templates. The problem is with setters, because even if you generate a method with the what seems to be an appropriate signature (*_$eq) it will not work. Scala compiler embeds some auxiliary info to the generated class to say that this method is a setter, etc. You won't get this from the java compiler. I learnt it the hard way [1] Smile

/cheers
Filip

[1] http://stackoverflow.com/questions/10897307/scala-getters-and-setters-in-java-class
Previous Topic:[CDO 4.1] : Adapter of ResourceSet of remote user not notified on Resource add/remove
Next Topic:[CDO]Again "selected specification is unresolved" errors.
Goto Forum:
  


Current Time: Thu Apr 25 01:36:16 GMT 2024

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

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

Back to the top