Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Generating code from ecore model (How to generate code from ecore model with OCL expressions in the separate file?)
Generating code from ecore model [message #1824122] Wed, 08 April 2020 09:38 Go to next message
Alex SuperStrongDino is currently offline Alex SuperStrongDinoFriend
Messages: 3
Registered: April 2020
Junior Member
I'm using Eclipse addon to work with OCL. I have an Ecore model with some operations and derived attributes also I have a separate OCL file with expressions in it. I made a genmodel file and added:
<genAnnotations source="http://www.eclipse.org/OCL/GenModel">
    <details key="Use Delegates" value="false"/>
</genAnnotations>

Also I checked that in the preferences realisation of OCL embedded within ecore models set to generate code. But when I try to generate code using this genmodel it only generates code without OCL expressions in it. What else should I do to generate code for all OCL expressions from a separate file?
  • Attachment: CarRental.7z
    (Size: 32.06KB, Downloaded 77 times)
Re: Generating code from ecore model [message #1824158 is a reply to message #1824122] Wed, 08 April 2020 19:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
HI

My copy of WinZip reports an unknown compression method.

Certainly I have never see a *.7z before. What is wrong with *.zip as created by Eclipse's Export Archive?

Regards

Ed Willink
Re: Generating code from ecore model [message #1824191 is a reply to message #1824158] Thu, 09 April 2020 10:18 Go to previous messageGo to next message
Alex SuperStrongDino is currently offline Alex SuperStrongDinoFriend
Messages: 3
Registered: April 2020
Junior Member
Sorry, I just compressed folder with my default archivator. Here is zip archive.
  • Attachment: project.zip
    (Size: 49.37KB, Downloaded 99 times)
Re: Generating code from ecore model [message #1824207 is a reply to message #1824191] Thu, 09 April 2020 15:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The problem is that while you have declared the names of many invariants, you have not defined any OCL expressions to implement them, consequently the OCL enrichment for GenModel concludes no-OCL, don't add OCL support ...

Read the Tutorial.

NB Do not use OCL 6.10.0 in which OCLinEcore save is broken. Other versions ok.

Regards

Ed Willink
Re: Generating code from ecore model [message #1824228 is a reply to message #1824207] Fri, 10 April 2020 10:32 Go to previous messageGo to next message
Alex SuperStrongDino is currently offline Alex SuperStrongDinoFriend
Messages: 3
Registered: April 2020
Junior Member
Sorry, but I'm still don't get it. I have bodies for implementation of these invariants in a separate OCL file. Why doesn't it generate code from this file? I also tried to generate code from a sample RoalAndLoyal project and it generates code with TODO instead of separate OCL file implementations. Maybe I don't understand something globally about OCL in Eclipse.
Re: Generating code from ecore model [message #1824232 is a reply to message #1824122] Fri, 10 April 2020 13:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The whole point of OCLinEcore is that it is OCL-IN-Ecore, you don't need a separate file. It leverages the standard Ecore functionality to generate code for the OCL at the same time as you generate the code for the Ecore model. No special tooling/procedures required by the user.

Separate OCL doesn't make much sense for code generation since you won't have any access to "this". It isn't supported, except in so far as you merge the OCL into the Ecore.

wrt the RoyalAndLoyal project, the TODOs sound like you didn't suppress delegates or may be there are some derived properties without bodies. .. or maybe there's a bug. I doubt anyone has done it before.

Regards

Ed Willink
Re: Generating code from ecore model [message #1824246 is a reply to message #1824228] Fri, 10 April 2020 15:46 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 104
Registered: December 2015
Location: Grenoble, France
Senior Member
@Alex SuperStrongDino

You do not seem to grasp the difference between OCLInEcore and Complete OCL (separate .ocl files)

If you want to add invariants, bodies or derived attributes to an ecore model, you use the OCLinEcore editor. The information is stored directly into the .ecore file, you do not need separate files, and it will be taken into account automatically when you generate the java code.

You only need to open your .ecore file with OCLInEcore editor (just right-click the .ecore file and select the popup menu entry " open with > OCLInEcore Editor")

have you followed these tutorials?

https://help.eclipse.org/2020-03/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FTutorials.html&cp%3D69_3_0&anchor=OCLinEcoreTutorial

https://help.eclipse.org/2020-03/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FCodeGenerationTutorial.html&cp%3D68_3_3

Complete OCL is not directly related to ecore code generation, and has other usages (for instance, I personally use it to implement programmatic validation for UML models)

Hope this help you clarify the different usage scenarios of eclipse OCL

[Updated on: Fri, 10 April 2020 15:59]

Report message to a moderator

Re: Generating code from ecore model [message #1824253 is a reply to message #1824246] Fri, 10 April 2020 19:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

(As I commented earlier, Complete OCL can be used for code generation after a merge. The Pivot OCL build merges a UML-derived Pivot.ecore with Pivot.ocl and then code generates. You can now merge interactively.)

Regards

ED Willink
Re: Generating code from ecore model [message #1824263 is a reply to message #1824253] Sat, 11 April 2020 11:57 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 104
Registered: December 2015
Location: Grenoble, France
Senior Member
Hi Ed,

Sorry to divert this thread, but I am very interested in the interactive merge of Complete OCL files.

Is this feature documented somewhere? I can not find it in the latest documentation or release notes.

When you say "The Pivot OCL build merges a UML-derived Pivot.ecore", does this mean that this is somehow related to java generation for UML models?

Regards.
Re: Generating code from ecore model [message #1824266 is a reply to message #1824263] Sat, 11 April 2020 14:22 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

/org.eclipse.ocl.examples.build/src/org/eclipse/ocl/examples/build/GeneratePivotModel.mwe2 is where the ((UML via QVTo to Ecore) + OCL) to Java happens (programmatically from Java). I'm losing patience with the idea of supporting all the stupid unprototyped things introduced by the OCL 2 specification, so the UML via QVTo to Ecore might vanish.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=500551 details my progress on supporting Merge. It is still open, so maybe my memory fails me. Looking at the menus, I suspect OCL->Load Document is basically a merge.

Regards

Ed Willink
Re: Generating code from ecore model [message #1824267 is a reply to message #1824266] Sat, 11 April 2020 14:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You might find /org.eclipse.qvtd.build/src/org/eclipse/qvtd/build/mwe2/GenerateQVTdASModels.mwe2 much easier to follow since it's just multiple *.ecore + *.ocl to *.java.

Regards

Ed Willink
Re: Generating code from ecore model [message #1824279 is a reply to message #1824267] Sun, 12 April 2020 13:24 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 104
Registered: December 2015
Location: Grenoble, France
Senior Member
Hi Ed,

Currently I use CompleteOCL for validation only, so I am basically reusing CompleteOCLLoader as a black-box.

But we are evaluating let the final users of our tool write OCL expressions to customize our UML generator (not targeting java, and written in QVTo) so I may take some inspiration from your code , thank you for the pointers
Re: Generating code from ecore model [message #1824281 is a reply to message #1824279] Sun, 12 April 2020 16:22 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I'm not sure if I understand. Your UML generator presumably produces code rather than UML, so you would need an OCL to something code generator. The OCL2Java plugin is written with the intention of supporting other OO-like languages, but it is only an intention. The plugin is the third incarnation of the CG and awaits a fourth with a clearer intermediate model. I would strongly caution against thinking that OCL2anyLanguage is easy. It is superficially easy but once you look for 100% rather than 90% simple idiom coverage it needs a genuine generator rather than a text template substituter.

Regards

Ed Willink
Re: Generating code from ecore model [message #1824283 is a reply to message #1824281] Sun, 12 April 2020 17:44 Go to previous message
German Vega is currently offline German VegaFriend
Messages: 104
Registered: December 2015
Location: Grenoble, France
Senior Member
Hi Ed,

Thanks for the remarks, sure OCL2anyLanguage is not easy endeavor. In my case the target language is not even OO but a logical formal language, and we do not expect to cover even 90% of OCL, but rather a restricted subset of OCL. So I do not expect to be able to reuse much of your existing generation code, I am looking
more for inspiration for the architecture of the translation chain. Your terrific work on eclipse OCL already makes our work feasible, otherwise we would have not even embarked in trying to use OCL for our tool.

Regards

G. Vega
Previous Topic:OCLinEcore metamodel and allinstances
Next Topic:CompleteOCL - Import URI
Goto Forum:
  


Current Time: Sun May 05 19:57:33 GMT 2024

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

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

Back to the top