Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL closure() ends in OclInvalid(Trying to get a certain subclass of a superclass with OCL closure() ends in OclInvalid)
OCL closure() ends in OclInvalid [message #1429790] Tue, 23 September 2014 19:15 Go to next message
Corinna K is currently offline Corinna KFriend
Messages: 2
Registered: September 2014
Junior Member
I have an abstract class A and two subclasses B and C inherit from A. The class C has also a composite relation to A, so in the tree-based editor C is like a parent class and can have some children (B & C), C can have further children and so on. In this case a recursion is necessary.

By using OCL closure() I'm trying to get all my childclasses B. Classes who are only childs and no parents. So I tried to collect all parents of C and wanted to get its children of class B.

I used this constraint:
C -> closure(v:C | v.compositeRelation.oclAsType(C)) //for collecting the parents

If I have only Cs and no Bs in my tree, the constraint works fine, but when there are also Bs I'm getting OclInvalid back.

I think a part in my constraint is missing for filter that the closure method should ignore Bs. All of my attempts are unsuccesful.

Thank you very much for your help!

[Updated on: Wed, 24 September 2014 08:10]

Report message to a moderator

Re: OCL closure() ends in OclInvalid [message #1429842 is a reply to message #1429790] Tue, 23 September 2014 20:42 Go to previous messageGo to next message
Vlad Gheorghe is currently offline Vlad GheorgheFriend
Messages: 127
Registered: May 2011
Senior Member
Hello Corinna,

In case v.compositeRelation contains an instance of B, the expression
v.compositeRelation.oclAsType(C) is invalid.

You should probably rewrite the expression using selectByType/selectByKind.

One other suggestion is to start with a small expression in the ocl console, and build it up incrementally, testing at each iteration.

Regards
Vlad Gheorghe
Re: OCL closure() ends in OclInvalid [message #1430278 is a reply to message #1429790] Wed, 24 September 2014 07:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5517
Registered: July 2009
Senior Member
Hi

Or, as of Luna, you can use the OCL debugger.

But as Vlad writes you need selectByKind (not selectByType) to avoid a
cast failure.

C->closure(compositeRelation->selectByKind(B))

[as with oclIsKindOf/oclIsTypeOf, you just about never want to use the
'Type' version.]


Regards

Ed Willink

On 23/09/2014 21:24, Corinna Kirner wrote:
> I have an abstract class A and two subclasses B and C inherit from A.
> The class C has also a composite relation to A, so in the tree-based
> editor C is like a parent class and can have some children (B & C), C
> can have further children and so on. In this case a recursion is necessary.
>
> By using OCL closure() I'm trying to get all my childclasses B. Classes
> who are only childs and no parents. So I tried to collect all parents of
> C and wanted to get its children of class B.
>
> I used this constraint:
> C -> closure(v:C | v.compositeRelation.oclAsType(C)) //for collecting
> the parents
> -> collect(v:C|v.compositeRelation) -> selectByKind(B) //for getting only B
>
> If I have only Cs and no Bs in my tree, the constraint works fine, but
> when there are also Bs I'm getting OclInvalid back.
>
> I think a part in my constraint is missing for filter that the closure
> method should ignore Bs. All of my attempts are unsuccesful.
>
> Thank you very much for your help!
>
Re: OCL closure() ends in OclInvalid [message #1430305 is a reply to message #1430278] Wed, 24 September 2014 08:27 Go to previous message
Corinna K is currently offline Corinna KFriend
Messages: 2
Registered: September 2014
Junior Member
The constraint is now working Smile
Thank you very much for your help!
Previous Topic:What is the allInstances counterpart for Associations in OCL?
Next Topic:Writing ocl for Metaclass association
Goto Forum:
  


Current Time: Mon Dec 11 19:25:06 GMT 2017

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

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