Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Global operation for oclAny
Global operation for oclAny [message #1726348] Fri, 11 March 2016 16:33 Go to next message
Nils Przigoda is currently offline Nils PrzigodaFriend
Messages: 14
Registered: September 2013
Location: Bremen, Germany
Junior Member
Hi all,

while reading some of the last topics (e.g. 1, 2) I got the idea to play a little bit with operations inside an OCL file (not OCLinEcore).

My goal was define an operation which can be called on any OCLExpression, like e.g. oclIsUndefined can. Reading the others topics and using google was very helpful, but now I'm getting stucked at the following point:

import MyEcoreModel : 'MyEcoreModel.ecore#/'
import oclTypes : 'http://www.eclipse.org/ocl/1.1.0/OCL/Types'

context oclTypes::AnyType def: newGlobalOperation(arg : oclTypes::AnyType) : oclTypes::AnyType = null

package MyEcoreModel
context MyClass1
    inv test : self.newGlobalOperation(true)
endpackage


In the invariant test there is no operation "newGlobalOperation" available, I do not understand why. Adding the operation to the class directly as follows works:

import MyEcoreModel : 'MyEcoreModel.ecore#/'
import oclTypes : 'http://www.eclipse.org/ocl/1.1.0/OCL/Types'

package MyEcoreModel
context MyClass1
    def: newGlobalOperation(arg : oclTypes::AnyType) : oclTypes::AnyType = null
    inv test : self.newGlobalOperation() 
endpackage


But there are two problems: First, the parameter/argument has been omitted and when I'm trying to add it, the invariant could not be parsed. Second, The newGlobalOperation is only available the MyClass1, but not for MyClass2.

Can anyone help me with this problem?

Regards,
Nils


Re: Global operation for oclAny [message #1726350 is a reply to message #1726348] Fri, 11 March 2016 17:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

There are two Eclipse OCL's.

The Classic Eclipse OCL supports an Ecore and a UML binding. It has a
number of limitations particularly in regard to extensibility.

'http://www.eclipse.org/ocl/1.1.0/OCL/Types' is the Library URI for the
Classic implementation.

The new Unified Pivot-based Eclipse OCL prototypes an extensible
UML-aligned implementation. It has an extensible library, with an Xtext
editor for it. It also has an Xtext editor for a Complete OCL document.

Using Complete OCL you can do something like

package ocl
context OCLExpression
def newGlobalOperation(arg : OclAny) : OclAny

But as I write this, I am really confused by your example. I don't see
why you use AnyType at all to define something for OCLExpression. It is
all at the wrong metalevel. You probably want to define

package ocl
context OclElement
def newGlobalOperation(arg : OclAny) : OclAny ...

since the Pivot-based OCL prototypes an OCL specification that
OclElement is the implicit supertype of all user-defined types (e.g.
MyClass1).

[OCL 2.0 had a special type called OclElement, but did not explain what
it was for and did not use it for anything. OCL 2.2 therefore removed
it. The Pivot-based OCL re-introduces it with a modeled definition. See

http://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/plugins/org.eclipse.ocl.pivot/model/OCL-2.5.oclstdlib
]

Regards

Ed Willink

On 11/03/2016 16:33, Nils Przigoda wrote:
> Hi all,
>
> while reading some of the last topics (e.g.
> https://www.eclipse.org/forums/index.php/t/1074939/,
> https://www.eclipse.org/forums/index.php/t/1073767/) I got the idea to
> play a little bit with operations inside an OCL file (not OCLinEcore).
>
> My goal was define an operation which can be called on any
> OCLExpression, like e.g. oclIsUndefined can. Reading the others topics
> and using google was very helpful, but now I'm getting stucked at the
> following point:
>
>
> import MyEcoreModel : 'MyEcoreModel.ecore#/'
> import oclTypes : 'http://www.eclipse.org/ocl/1.1.0/OCL/Types'
>
> context oclTypes::AnyType def: newGlobalOperation(arg :
> oclTypes::AnyType) : oclTypes::AnyType = null
>
> package MyEcoreModel
> context MyClass1
> inv test : self.newGlobalOperation(true)
> endpackage
>
>
> In the invariant test there is no operation "newGlobalOperation"
> available, I do not understand why. Adding the operation to the class
> directly as follows works:
>
>
> import MyEcoreModel : 'MyEcoreModel.ecore#/'
> import oclTypes : 'http://www.eclipse.org/ocl/1.1.0/OCL/Types'
>
> package MyEcoreModel
> context MyClass1
> def: newGlobalOperation(arg : oclTypes::AnyType) :
> oclTypes::AnyType = null
> inv test : self.newGlobalOperation() endpackage
>
>
> But there are two problems: First, the parameter/argument has been
> omitted and when I'm trying to add it, the invariant could not be
> parsed. Second, The newGlobalOperation is only available the MyClass1,
> but not for MyClass2.
>
> Can anyone help me with this problem?
>
> Regards,
> Nils
>
>
>
Re: Global operation for oclAny [message #1726424 is a reply to message #1726350] Sun, 13 March 2016 12:04 Go to previous messageGo to next message
Nils Przigoda is currently offline Nils PrzigodaFriend
Messages: 14
Registered: September 2013
Location: Bremen, Germany
Junior Member
Hi Ed,

thanks for your answer! I tried OCLExpression besides the AnyType, but OclElement was not coming into my mind, because I was only trying the classical OCL. However, with the following lines it does work for me in the OCL editor:

import MyEcoreModel : 'MyEcoreModel.ecore#/'
import ocl : 'http://www.eclipse.org/ocl/3.1.0/Pivot'

context ocl::OclElement def: newGlobalOperation(a : OclAny) : OclAny = null

package MyEcoreModel
context MyClass1
    inv test1 : self.newGlobalOperation(true)
context MyClass2
    inv test2 : self.newGlobalOperation(true)
endpackage


One problem is still existing, when I'm parsing the document, I'm getting an exception:

org.eclipse.ocl.SyntaxException: 2:1:2:53 "import ocl : 'http://www.eclipse.org/ocl/3.1.0/Pivot'" misplaced construct(s)
	at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:350)
	at org.eclipse.ocl.OCL.parse(OCL.java:317)
...


I'm sure that it means that have to organize an import of the OCL pivot file, but how can I do so?

Regards
Nils
Re: Global operation for oclAny [message #1726438 is a reply to message #1726424] Sun, 13 March 2016 15:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

Try

import ocl : 'http://www.eclipse.org/ocl/2015/Pivot'

http://www.eclipse.org/ocl/3.1.0/Pivot is the pre-Mars nsURI before the
Pivot-based code was promoted from examples. I (or more likely lack of
time) decided against providing a backward migration.

Regards

Ed Willink

On 13/03/2016 12:04, Nils Przigoda wrote:
> Hi Ed,
>
> thanks for your answer! I tried OCLExpression besides the AnyType, but
> OclElement was not coming into my mind, because I was only trying the
> classical OCL. However, with the following lines it does work for me
> in the OCL editor:
>
>
> import MyEcoreModel : 'MyEcoreModel.ecore#/'
> import ocl : 'http://www.eclipse.org/ocl/3.1.0/Pivot'
>
> context ocl::OclElement def: newGlobalOperation(a : OclAny) : OclAny =
> null
>
> package MyEcoreModel
> context MyClass1
> inv test1 : self.newGlobalOperation(true)
> context MyClass2
> inv test2 : self.newGlobalOperation(true)
> endpackage
>
>
> One problem is still existing, when I'm parsing the document, I'm
> getting an exception:
>
> org.eclipse.ocl.SyntaxException: 2:1:2:53 "import ocl :
> 'http://www.eclipse.org/ocl/3.1.0/Pivot'" misplaced construct(s)
> at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:350)
> at org.eclipse.ocl.OCL.parse(OCL.java:317)
> ..
>
>
> I'm sure that it means that have to organize an import of the OCL
> pivot file, but how can I do so?
>
> Regards
> Nils
>
Re: Global operation for oclAny [message #1726441 is a reply to message #1726438] Sun, 13 March 2016 19:06 Go to previous messageGo to next message
Nils Przigoda is currently offline Nils PrzigodaFriend
Messages: 14
Registered: September 2013
Location: Bremen, Germany
Junior Member
I've just tried it with
import ocl : 'http://www.eclipse.org/ocl/2015/Pivot'

in Eclipse Mars, and the errors is still the same.
Re: Global operation for oclAny [message #1726563 is a reply to message #1726441] Mon, 14 March 2016 16:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

It works fine for me even with the old nsURI in Mars.2.

This is a waste of both our times. I should have insisted on a full
repro: See https://wiki.eclipse.org/OCL/ForumNetiquette

Regards

Ed Willink


On 13/03/2016 19:06, Nils Przigoda wrote:
> I've just tried it with
> import ocl : 'http://www.eclipse.org/ocl/2015/Pivot'
> in Eclipse Mars, and the errors is still the same.
Re: Global operation for oclAny [message #1727081 is a reply to message #1726348] Fri, 18 March 2016 17:22 Go to previous messageGo to next message
Nils Przigoda is currently offline Nils PrzigodaFriend
Messages: 14
Registered: September 2013
Location: Bremen, Germany
Junior Member
Here is zip-file of mini project where I re-produced the above mentioned exception with

Version: Mars.1 Release (4.5.1)
Build id: 20150924-1200

Please let me know what I'm doing wrong, thanks in advance!
Re: Global operation for oclAny [message #1727096 is a reply to message #1727081] Fri, 18 March 2016 21:36 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

You are mixing Classic and Pivot OCL.

When you import org.eclipse.ocl.ecore you use the old Ecore Parser that
has no support for import statements; rather you need to magically load
the EPackage.Registry programmatically and install additional features
programmatically.

If you look in the documentation you will find the same example for OCL
parsing for both variants. If you want the newer moree flexioble
Pivt-based OCL then use it consistentluy.

Regards

Ed Willink


On 18/03/2016 17:22, Nils Przigoda wrote:
> Here is zip-file of mini project where I re-produced the above mentioned exception with
>
> Version: Mars.1 Release (4.5.1)
> Build id: 20150924-1200
>
> Please let me know what I'm doing wrong, thanks in advance!
>
Re: Global operation for oclAny [message #1728934 is a reply to message #1727096] Fri, 08 April 2016 13:53 Go to previous messageGo to next message
Nils Przigoda is currently offline Nils PrzigodaFriend
Messages: 14
Registered: September 2013
Location: Bremen, Germany
Junior Member
Hi Ed, thanks a lot! I did not realized that I was mixing it. After playing a little bit I've now implemented your ideas (i.e. using OclElement) and updated the project configuration and code. However, there is still some unexpected behavior, at least to me. To make the example a bit more realistic, I tried to define an oclIsDefined method as global operation using the following line:
context ocl::OclElement def: oclIsDefined() : Boolean = null

But this does not work on a probably undefined Boolean attribute. For example, parsing the invariant
inv inv2 : self.boolAttr.oclIsDefined()
leads to
Constraint:	invariant inv2: self.boolAttr.oclBadOperation()

When adding an extra line in the OCL file
context ocl::Boolean def: oclIsDefined() : Boolean = null
this works.

I've attached a small project, where the error occurs.

I'm now asking myself: Why is OclElement not working on Booleans and also integers?
Re: Global operation for oclAny [message #1728953 is a reply to message #1728934] Fri, 08 April 2016 15:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

The inheritance relationships are all modelled in
/org.eclipse.ocl.pivot/model/OCL-2.5.oclstdlib so that in the
Pivot-based OCL prototype for a future OCL.

OclAny is the root implicit supertype of everything (currently including
CollectionTypes).

OclElement is the implicit supertype of user-defined classes (i.e not
PrimitiveTypes)

OclType is the implicit supertype of types.

Regards

Ed Willink

On 08/04/2016 14:53, Nils Przigoda wrote:
> Hi Ed, thanks a lot! I did not realized that I was mixing it. After playing a little bit I've now implemented your ideas (i.e. using OclElement) and updated the project configuration and code. However, there is still some unexpected behavior, at least to me. To make the example a bit more realistic, I tried to define an oclIsDefined method as global operation using the following line:
> context ocl::OclElement def: oclIsDefined() : Boolean = null
> But this does not work on a probably undefined Boolean attribute. For example, parsing the invariant inv inv2 : self.boolAttr.oclIsDefined() leads to Constraint: invariant inv2: self.boolAttr.oclBadOperation()
> When adding an extra line in the OCL file context ocl::Boolean def: oclIsDefined() : Boolean = null this works.
>
> I've attached a small project, where the error occurs.
>
> I'm now asking myself: Why is OclElement not working on Booleans and also integers?
Re: Global operation for oclAny [message #1728966 is a reply to message #1728953] Fri, 08 April 2016 17:19 Go to previous message
Nils Przigoda is currently offline Nils PrzigodaFriend
Messages: 14
Registered: September 2013
Location: Bremen, Germany
Junior Member
Thanks for the explanation, Ed! Changing OclElement it OclAny solved my problem!
Previous Topic:Computing derived attribute values with dynamic EMF
Next Topic:UML-OCL ; specifying constraints in the context of an association / association class
Goto Forum:
  


Current Time: Sat Sep 22 16:30:35 GMT 2018

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

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

Back to the top