Skip to main content



      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 10:56 Go to next message
Eclipse UserFriend
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 13:30 Go to previous messageGo to next message
Eclipse UserFriend
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 15:05 Go to previous messageGo to next message
Eclipse UserFriend
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 16:06 Go to previous messageGo to next message
Eclipse UserFriend
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 12:31 Go to previous message
Eclipse UserFriend
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: Mon Jul 07 19:55:42 EDT 2025

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

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

Back to the top