Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Specification of operation bodies in 'plain Java' + OCL-based constraints(Specification of operation bodies in 'plain Java' + OCL-based constraints)
Specification of operation bodies in 'plain Java' + OCL-based constraints [message #1696494] Tue, 26 May 2015 17:15 Go to next message
Matthias Freund is currently offline Matthias FreundFriend
Messages: 8
Registered: May 2014
Junior Member
Hi all,

this is my situation:
In my metamodel, I have introduced some custom operations and specified their body via annotations with source 'http://www.eclipse.org/emf/2002/Ecore', key = "body" and a value in plain Java. Additionally, I have defined some OCL constraints for the parent EClass (The ".../OCL/Pivot" delegates are used just as in the "OCLin EcoreTutorial"). If I generate the model code, everything works fine and the constraints are validated properly in the editor.

Up to now, I have set the OCL preference "Realisation of OCL embedded within Ecore models" to "Delegate for interpretation at runtime." Now, I want to generate Java code for the OCL constraints by setting the value of the preference to "Generate Java Code in *Impl classes".

However, when I regenerate the model code, the custom operations are not generated properly any more -- instead, they only contain a "throw new UnsupportedOperationException();" statement.

My question is whether this is a bug or if it is now allowed to mix OCL-based invariants with operation body specifications in plain Java. Do I have to specify the bodies of my operations in OCL as well or is there any other solution?

Thanks in advance!
Matthias
Re: Specification of operation bodies in 'plain Java' + OCL-based constraints [message #1696502 is a reply to message #1696494] Tue, 26 May 2015 19:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5967
Registered: July 2009
Senior Member
Hi

I hadn't considered this, but it should just work.

The OCLinEcore CG just does what you do, it adds
'http://www.eclipse.org/emf/2002/Ecore' "body" EAnnotations to an
in-memory copy of the model in a pre-generate phase.

But beware, you need to restart the GenModel editor after making model
changes, since the additions to the in-memory model do not work well if
added a second time. This is a known bug.

Regards

Ed Willink


On 26/05/2015 18:15, Matthias Freund wrote:
> Hi all,
>
> this is my situation:
> In my metamodel, I have introduced some custom operations and
> specified their body via annotations with source
> 'http://www.eclipse.org/emf/2002/Ecore', key = "body" and a value in
> plain Java. Additionally, I have defined some OCL constraints for the
> parent EClass (The ".../OCL/Pivot" delegates are used just as in the
> "OCLin EcoreTutorial"). If I generate the model code, everything works
> fine and the constraints are validated properly in the editor.
>
> Up to now, I have set the OCL preference "Realisation of OCL embedded
> within Ecore models" to "Delegate for interpretation at runtime." Now,
> I want to generate Java code for the OCL constraints by setting the
> value of the preference to "Generate Java Code in *Impl classes".
>
> However, when I regenerate the model code, the custom operations are
> not generated properly any more -- instead, they only contain a "throw
> new UnsupportedOperationException();" statement.
>
> My question is whether this is a bug or if it is now allowed to mix
> OCL-based invariants with operation body specifications in plain Java.
> Do I have to specify the bodies of my operations in OCL as well or is
> there any other solution?
>
> Thanks in advance!
> Matthias
Re: Specification of operation bodies in 'plain Java' + OCL-based constraints [message #1696533 is a reply to message #1696502] Wed, 27 May 2015 07:07 Go to previous messageGo to next message
Matthias Freund is currently offline Matthias FreundFriend
Messages: 8
Registered: May 2014
Junior Member
Hi,

thanks for you quick response. Unfortunately, I made a mistake in the description of my situation. The source of my annotations to generate the Java bodies of operations is of course http://www.eclipse.org/emf/2002/GenModel instead of http://www.eclipse.org/emf/2002/Ecore as described in the EMF book.

I get a "throw UnsupportedOperationException()" with both source namespaces, though.

You can try this with the "OCLinEcoreTutorial" if you change the source of the annotation for the "isAvailable()" operation of the EClass "Book" from http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot to http://www.eclipse.org/emf/2002/GenModel and the value of the annotation to "return true;" (for reasons of simplicity).

It works with the OCL preference "Delegate for interpretation at run-time" but does not with "Generate Java Code in *Impl classes" even if I restart the GenModel editor (or Eclipse).

Regards
Matthias

[Updated on: Wed, 27 May 2015 07:08]

Report message to a moderator

Re: Specification of operation bodies in 'plain Java' + OCL-based constraints [message #1696554 is a reply to message #1696533] Wed, 27 May 2015 09:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5967
Registered: July 2009
Senior Member
On 27/05/2015 08:07, Matthias Freund wrote:
> You can try this with the "OCLinEcoreTutorial" if you change the
> source of the annotation for the "isAvailable()" operation of the
> EClass "Book" from http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot to
> http://www.eclipse.org/emf/2002/GenModel and the value of the
> annotation to "return true;" (for reasons of simplicity).
Thanks. https://bugs.eclipse.org/bugs/show_bug.cgi?id=468444 raised.

Should be fixed in Mars RC3 or an N-build later today.

Regards

Ed Willink
Re: Specification of operation bodies in 'plain Java' + OCL-based constraints [message #1696565 is a reply to message #1696554] Wed, 27 May 2015 09:45 Go to previous message
Matthias Freund is currently offline Matthias FreundFriend
Messages: 8
Registered: May 2014
Junior Member
Great! Thanks very much.

Regards
Matthias
Previous Topic:Handy API to execute OCL expressions from java code
Next Topic:Possible bug in generated code
Goto Forum:
  


Current Time: Sun Jul 15 21:11:25 GMT 2018

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

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

Back to the top