Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How do I model a statically defined constant?
How do I model a statically defined constant? [message #500551] Thu, 26 November 2009 15:56 Go to next message
Thomas Hallgren is currently offline Thomas HallgrenFriend
Messages: 3240
Registered: July 2009
Senior Member
Hi,
I want my generated Java interface to contain a declaration like this:

static final String FOOBAR = "foobar";

and I would like to reflect this in the ecore model. I've tried to find ways to do that but didn't succeed. Is it possible?

Regards,
Thomas Hallgren
Re: How do I model a statically defined constant? [message #500566 is a reply to message #500551] Thu, 26 November 2009 18:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30653
Registered: July 2009
Senior Member
Thomas,

There's no corresponding concept in Ecore so you'll have to add it by hand.


Thomas Hallgren wrote:
> Hi,
> I want my generated Java interface to contain a declaration like this:
>
> static final String FOOBAR = "foobar";
>
> and I would like to reflect this in the ecore model. I've tried to
> find ways to do that but didn't succeed. Is it possible?
>
> Regards,
> Thomas Hallgren
Re: How do I model a statically defined constant? [message #502164 is a reply to message #500566] Sun, 06 December 2009 20:05 Go to previous messageGo to next message
gary s thompson is currently offline gary s thompsonFriend
Messages: 83
Registered: July 2009
Member
here is the recipe I used to go about it (this is just what I did but seems to follow the correct methodology, use of annotations etc but hasn't been looked at by anyone else
so ymmv)

1. create an annotation in the relevant class to define the annotation

<eAnnotations source=" http://www.leeds.ac.uk/xxxx-ecore-1.0/ccpn_genmodel/class_st atic">
<details key="attribute_type" value="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>
<details key="attribute_name" value="XXXX_YYYY"/>
<details key="attribute_default_value" value=-1"/>
</eAnnotations>

2. follow the instructions to use dynamic jet templates
http://blog.eclipse-tips.com/2008/08/using-dynamic-templates -in-emf.html
or http://wiki.eclipse.org/EMF/FAQ#How_do_I_use_Dynamic_Templat es.3F

3. edit the Class.javajet file (or one of the files it inclusdes) to add you changes so
a. when the class body starts search the class for all annotations of your type on the ecore class refered to by the gen model class genClass.getEcoreClass()
b. pull out the attributes
c. lookup the type from the gen model
d. output the correct data 'static final <%className%> <%classType%> = <%defaultValue%>

a warning I doubt you static types will update properly when you update your model rather than creating it for the first time (I may be wrong on this point Wink as jmerge won't know about statics
Re: How do I model a statically defined constant? [message #502170 is a reply to message #502164] Sun, 06 December 2009 21:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30653
Registered: July 2009
Senior Member
Gary,

JMerge should work well with all Java constructs. After all, generated
classes often have static final constants. Of course it's redundant to
use static and final in an interface.


gary s thompson wrote:
> here is the recipe I used to go about it (this is just what I did but
> seems to follow the correct methodology, use of annotations etc but
> hasn't been looked at by anyone else
> so ymmv)
>
> 1. create an annotation in the relevant class to define the annotation
>
> <eAnnotations
> source=" http://www.leeds.ac.uk/xxxx-ecore-1.0/ccpn_genmodel/class_st atic">
>
> <details key="attribute_type"
> value="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>
> <details key="attribute_name" value="XXXX_YYYY"/>
> <details key="attribute_default_value" value=-1"/>
> </eAnnotations>
>
> 2. follow the instructions to use dynamic jet templates
> http://blog.eclipse-tips.com/2008/08/using-dynamic-templates -in-emf.html
> or http://wiki.eclipse.org/EMF/FAQ#How_do_I_use_Dynamic_Templat es.3F
>
> 3. edit the Class.javajet file (or one of the files it inclusdes) to
> add you changes so
> a. when the class body starts search the class for all annotations of
> your type on the ecore class refered to by the gen model class
> genClass.getEcoreClass()
> b. pull out the attributes c. lookup the type from the gen model
> d. output the correct data 'static final <%className%> <%classType%>
> = <%defaultValue%>
>
> a warning I doubt you static types will update properly when you
> update your model rather than creating it for the first time (I may be
> wrong on this point ;) as jmerge won't know about statics
Re: How do I model a statically defined constant? [message #502792 is a reply to message #502170] Wed, 09 December 2009 17:31 Go to previous message
gary s thompson is currently offline gary s thompsonFriend
Messages: 83
Registered: July 2009
Member
yes I agree that static final in an interface is wasted typing. I haven't used this recipe on interfaces but have on classes. Wink

As an after though I presume I should have added that anything you generate should have an @generated comment and I guess thats why some of my fields weren't updated properly....

regards
gary
Previous Topic:[CDO] Walking the graph of a revision
Next Topic:ResourceImpl and delegation to XMIResourceImpl
Goto Forum:
  


Current Time: Fri Nov 22 07:12:29 GMT 2019

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

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

Back to the top