Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Ecore - method bodies
Ecore - method bodies [message #1794488] Fri, 31 August 2018 09:26 Go to next message
hey you is currently offline hey youFriend
Messages: 15
Registered: July 2018
Junior Member
Hello everyone,

I am pretty new to Ecore, and I would like to ask if it's possible to fill the method bodies with the generated code. I know one can use OCL to make preconditions and postconditions for the methods, but is it's possible to autogenerate method body code as well? I believe adding body code to the autogenerated method manually is very bad idea if I regenerate my model again.

What is the alternative that Ecore provides? I found here https://www.eclipse.org/modeling/emf/docs/presentations/EclipseCon/EclipseCon2006_EMF_Intro.pdf , that one can use annotations e.g. "@generated NOT", but I think this is only not regenerating the method again.

Also I couldn't figure out what is a syntax for preconditions and postconditions in OCLInEcore. Usual OCL syntax:
context <classifier>::<operation> (<parameters>)
pre [<constraint name>]:
<Boolean OCL expression>
did not work for me.

e.g.
class Web
{
operation addKeyword(keyword : String[?])
{
pre: not keyword.oclIsUndefined();
}
}

Another question is, does Ecore support C++ code generation or only Java is supported?

Thank you in advance,
Ivan
Re: Ecore - method bodies [message #1794490 is a reply to message #1794488] Fri, 31 August 2018 09:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Like in OCLInEcore, with Xcore your can also define your operation bodies in the model:

https://wiki.eclipse.org/Xcore

Both approaches rely on automatically generating a "body" annotation on the EOperation, so you can also do that directly in Ecore itself with an EAnnotation with source http://www.eclipse.org/emf/2002/GenModel and a detail key "body" where the value of that detail is the Java code to be generated.

The Ecore editor for Photon makes it easy to create such annotations because the specialized properties view for defining GenModel annotations as well as specialized creation support for creating the GenModel annotation.

No, there is no support for generating language other than Java.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Ecore - method bodies [message #1794497 is a reply to message #1794490] Fri, 31 August 2018 12:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

In OCLinEcore you can cause the "precondition" or "postcondition" keywords in the same way as the "invariant" keyword.

However pre/post-conditions are only syntax checked. When OCL was interpreted it was doubtful that anyone wanted the interpreted performance hit of pre/post-condition evaluation. Now that Java code generation is available, generating pre/post-condition code is on my to-do list, but quite a long way down. A further disincentive is that I do not know how to implement @pre since for the pathological general case it requires a total system copy on entry to an operation with an @pre postcondition!

If I had even as many as one user request for this per year I might be more inclined to try to tackle it.

Regards

Ed Willink
Re: Ecore - method bodies [message #1794706 is a reply to message #1794490] Wed, 05 September 2018 09:37 Go to previous messageGo to next message
Jan-Patrick Osterloh is currently offline Jan-Patrick OsterlohFriend
Messages: 6
Registered: September 2014
Junior Member
Hi,

Ed Merks wrote on Fri, 31 August 2018 09:46

The Ecore editor for Photon makes it easy to create such annotations because the specialized properties view for defining GenModel annotations as well as specialized creation support for creating the GenModel annotation.


Sorry, and maybe this question is stupid, but I recently switched to Photon, and have now some difficulties with the EMF editor. While adding the GenModel Annotation is now very easy, editing the "body" part is difficult, because it allows only one line of code. Previously, I could open a multi-line editor, but this is not longer possible. Am I missing a certain plugin, or is there a new way of doing it?

Best
Jan-Patrick
Re: Ecore - method bodies [message #1794753 is a reply to message #1794706] Thu, 06 September 2018 06:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
The new properties added to the GenModel for EMF 2.14 to support these properties weren't set to support multi-line values. I opened:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=538664

and the fix is available by updating from:

http://download.eclipse.org/modeling/emf/emf/builds/milestone


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Ecore - method bodies [message #1794796 is a reply to message #1794753] Thu, 06 September 2018 15:25 Go to previous message
Jan-Patrick Osterloh is currently offline Jan-Patrick OsterlohFriend
Messages: 6
Registered: September 2014
Junior Member
Thank you very much Ed! That works!
Previous Topic:Ecore: Type parameter for interface implementation?
Next Topic:[CDO] Offline Clone: simultanous commits on master and clone cause timeout
Goto Forum:
  


Current Time: Fri Apr 19 01:37:15 GMT 2024

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

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

Back to the top