Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Texo] create code depending on a user defined annotation
[Texo] create code depending on a user defined annotation [message #1328659] Fri, 02 May 2014 20:24 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Hi all,
I want to create some of my entities as Java beans (with
PropertyChangeSupport). Therefore I have added an EAnnotation attribute
to my ecore model classes. Now I want to access this annotation from
inside a texo template. I prepared a user defined generator template in
my project but I don't know how to access the new annotation. Is there a
tutorial for it?

Thanks,
Ralf.
Re: [Texo] create code depending on a user defined annotation [message #1331872 is a reply to message #1328659] Sun, 04 May 2014 10:08 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Ralf,
No direct tutorial, but it is quite easy since you have a handle to the EClass, for example the EntityTemplate has these
code snippets:
«modelController.getJavaAnnotations(eClassModelGenAnnotation.EClass, "type", eClassModelGenAnnotation.EClass)»

The eClassModelGenAnnotation.EClass is the eClass object, you can use the java api of the EClass to access eannotations.
For example:
eClassModelGenAnnotation.EClass.getEAnnotation("my custom source").details.get("mykey")

gr. Martin

On 02-05-14 22:24, Ralf Heydenreich wrote:
> Hi all,
> I want to create some of my entities as Java beans (with
> PropertyChangeSupport). Therefore I have added an EAnnotation attribute
> to my ecore model classes. Now I want to access this annotation from
> inside a texo template. I prepared a user defined generator template in
> my project but I don't know how to access the new annotation. Is there a
> tutorial for it?
>
> Thanks,
> Ralf.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] create code depending on a user defined annotation [message #1332809 is a reply to message #1331872] Sun, 04 May 2014 21:04 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Am 04.05.2014 12:08, schrieb Martin Taal:
> Hi Ralf,
> No direct tutorial, but it is quite easy since you have a handle to the
> EClass, for example the EntityTemplate has these code snippets:
> «modelController.getJavaAnnotations(eClassModelGenAnnotation.EClass,
> "type", eClassModelGenAnnotation.EClass)»
>
> The eClassModelGenAnnotation.EClass is the eClass object, you can use
> the java api of the EClass to access eannotations. For example:
> eClassModelGenAnnotation.EClass.getEAnnotation("my custom
> source").details.get("mykey")
>
> gr. Martin
>
Hi Martin,
thanks for your reply. But I didn't get it (yet)... What I've done:

First I added an EAnnotation to an EClass in my ecore model file (NOT
the annotation model!). Then I changed the entity.xpt template (after
generation of serialVersionUID):

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
«this.getEAnnotation("Bean")»
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


(You wrote that the eClassModelGenAnnotation.EClass is the eClass
object, therefore I assumed that I can use "this" inside the template.)
The result is that Texo complaints about
"java.lang.IllegalStateException: Couldn't find operation
'getEAnnotation(String)' for
org::eclipse::emf::texo::modelgenerator::modelannotations::EClassModelGenAnnotation."

How could I access the underlying ECore model?

What I want to achieve is that if I add a certain annotation to my
EClass (e.g., "@Bean"), then an additional code snippet should be
generated. But at the moment I'm unable to say it syntactically correct...

Regards,
Ralf.
Re: [Texo] create code depending on a user defined annotation [message #1333763 is a reply to message #1332809] Mon, 05 May 2014 08:04 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Ralf,
The this points to the eClassModelGenAnnotation not to the EClass, therefore you have to use:
this.EClass to get the EClass.

Then the getEAnnotation expects the source, it returns an EAnnotation object which has a details member, the details is
a map which contains the annotation string itself, the map key is often 'value' or some other identifier.

btw, this error message:
java.lang.IllegalStateException: Couldn't find operation
> 'getEAnnotation(String)' for
> org::eclipse::emf::texo::modelgenerator::modelannotations::EClassModelGenAnnotation.

tells you that the this is the EClassModelGenAnnotation and that this class does not have a getEAnnotation method. You
can find this class and its api to check it in Eclipse (use shft-ctrl-t).

gr. Martin

On 04-05-14 23:04, Ralf Heydenreich wrote:
> Am 04.05.2014 12:08, schrieb Martin Taal:
>> Hi Ralf,
>> No direct tutorial, but it is quite easy since you have a handle to the
>> EClass, for example the EntityTemplate has these code snippets:
>> «modelController.getJavaAnnotations(eClassModelGenAnnotation.EClass,
>> "type", eClassModelGenAnnotation.EClass)»
>>
>> The eClassModelGenAnnotation.EClass is the eClass object, you can use
>> the java api of the EClass to access eannotations. For example:
>> eClassModelGenAnnotation.EClass.getEAnnotation("my custom
>> source").details.get("mykey")
>>
>> gr. Martin
>>
> Hi Martin,
> thanks for your reply. But I didn't get it (yet)... What I've done:
>
> First I added an EAnnotation to an EClass in my ecore model file (NOT
> the annotation model!). Then I changed the entity.xpt template (after
> generation of serialVersionUID):
>
> /* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> «this.getEAnnotation("Bean")»
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
>
>
> (You wrote that the eClassModelGenAnnotation.EClass is the eClass
> object, therefore I assumed that I can use "this" inside the template.)
> The result is that Texo complaints about
> "java.lang.IllegalStateException: Couldn't find operation
> 'getEAnnotation(String)' for
> org::eclipse::emf::texo::modelgenerator::modelannotations::EClassModelGenAnnotation."
>
> How could I access the underlying ECore model?
>
> What I want to achieve is that if I add a certain annotation to my
> EClass (e.g., "@Bean"), then an additional code snippet should be
> generated. But at the moment I'm unable to say it syntactically correct...
>
> Regards,
> Ralf.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] create code depending on a user defined annotation [message #1337565 is a reply to message #1333763] Tue, 06 May 2014 23:00 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Am 05.05.2014 10:04, schrieb Martin Taal:
> Hi Ralf,
> The this points to the eClassModelGenAnnotation not to the EClass,
> therefore you have to use:
> this.EClass to get the EClass.
>
> Then the getEAnnotation expects the source, it returns an EAnnotation
> object which has a details member, the details is a map which contains
> the annotation string itself, the map key is often 'value' or some other
> identifier.
> [...]

Hi Martin,
it gets a little clearer, but I still don't get it to work. As an
example I would print the annotation in a remark:

/*
«this.EClass.getEAnnotation()»
*/

Since you said "it expects the source" I thought that I have to put the
current class itself into the method call:

/*
«this.EClass.getEAnnotation(this)»
*/

But this doesn't produced a result. Or do you mean:

«getEAnnotation(this.EClass)»

There's no example for that in the xpand sample files. Pleas provide me
an example (or a link to any documentation where I can get the solution
for my problem.Thanks in advance.

Regards,
Ralf.
Re: [Texo] create code depending on a user defined annotation [message #1337631 is a reply to message #1337565] Tue, 06 May 2014 23:43 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Ralf,
In this code snippet you are in fact not in xpand :-), you are using the java api provided by the EClass class. So any
information you should search for in the java api and not in xpand.
To clarify:
when you do: this.EClass in this xpand template then this is the EClass object itself, the EMF EClass object, you can
access its complete java api from here, for example calling getEAnnotation(String source):
> «this.EClass.getEAnnotation("texo.jpa")»
(note texo.jpa is just an example source)

If you want to know what you can call, do shift-ctrl-t from a java source and then type EClass as the search string.
This opens the EClass java source there you can find the methods you can call.

For the term 'source', an EAnnotation in EMF has a source and a key and a value. A source is the identifier of an
EAnnotation, the source is a string, often uri-like. The EAnnotation you get has a member called 'details'. The details
is a Map, the key is a string the value also. The key is often 'value' but it can be anything.

gr. MArtin

On 07-05-14 01:00, Ralf Heydenreich wrote:
> Am 05.05.2014 10:04, schrieb Martin Taal:
>> Hi Ralf,
>> The this points to the eClassModelGenAnnotation not to the EClass,
>> therefore you have to use:
>> this.EClass to get the EClass.
>>
>> Then the getEAnnotation expects the source, it returns an EAnnotation
>> object which has a details member, the details is a map which contains
>> the annotation string itself, the map key is often 'value' or some other
>> identifier.
>> [...]
>
> Hi Martin,
> it gets a little clearer, but I still don't get it to work. As an
> example I would print the annotation in a remark:
>
> /*
> «this.EClass.getEAnnotation()»
> */
>
> Since you said "it expects the source" I thought that I have to put the
> current class itself into the method call:
>
> /*
> «this.EClass.getEAnnotation(this)»
> */
>
> But this doesn't produced a result. Or do you mean:
>
> «getEAnnotation(this.EClass)»
>
> There's no example for that in the xpand sample files. Pleas provide me
> an example (or a link to any documentation where I can get the solution
> for my problem.Thanks in advance.
>
> Regards,
> Ralf.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:[Xcore] Copying content from one Xcore model to another programmatically
Next Topic:A general question about derived features in EMF
Goto Forum:
  


Current Time: Fri Mar 29 01:00:35 GMT 2024

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

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

Back to the top