Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Helper functions in OCL constraints
Helper functions in OCL constraints [message #988309] Thu, 29 November 2012 11:03 Go to next message
Cássio Santos is currently offline Cássio SantosFriend
Messages: 4
Registered: November 2012
Junior Member
The tutorial in:
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.ocl.doc/tutorials/oclinecore/oclInEcoreTutorial.html
show how to create helper functions and use it in invariants.

But after the transformation through the GMF process, the use of helper functions (described in the ecore model) in the editor constraints does not work.

Is there a way of create invariants that use helper functions in GMF?


----
Thanks,
Cássio
Re: Helper functions in OCL constraints [message #988797 is a reply to message #988309] Mon, 03 December 2012 09:03 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

did you test you OCL methods by using the ocl console as described in the article? What is the output at both the OCL console and in you eclipse console that you use for debuging?

Ralph
Re: Helper functions in OCL constraints [message #988946 is a reply to message #988797] Mon, 03 December 2012 23:50 Go to previous messageGo to next message
Cássio Santos is currently offline Cássio SantosFriend
Messages: 4
Registered: November 2012
Junior Member
After some more tests I've reached the core of my problem. I've managed to use helper functions but I couldn't specify the following OCL functions:

context Role::superrolePlus():Set(Role)
body: self.superrolePlusOnSet(self.superrole)

context Role::superrolePlusOnSet(rs:Set(Role)):Set(Role)
body:
if rs.superrole->exists(r|rs->excludes(r))
then self.superrolePlusOnSet(rs->union(rs.superrole)->asSet())
else rs->including(self)
endif

where Role is a model element, and superrole is a relationship that provides all the parents of a given Role.
The goal of this functions is calculate the transitive reflexive closure in Roles hierarchy. Through this I would be to able to specify invariants like no cicles in Role hierarchy.
The problem is: I can't specify the return of a operation in eCore to an OCL type(like Set), and I can't use the ecore types in OCL functions. There's a equivalence betweeen any eCore types and OCL types?

Thanks,
Re: Helper functions in OCL constraints [message #988991 is a reply to message #988946] Tue, 04 December 2012 07:58 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

do you use the syntax displayed in you OCL statements above? Can you paste some of you actual OCL code that you use? The OCL in you previous post doesn't look like what I have seen for OCLInEcore but maybe I am just not aware of something.

Ralph
Re: Helper functions in OCL constraints [message #989011 is a reply to message #988991] Tue, 04 December 2012 10:08 Go to previous messageGo to next message
Cássio Santos is currently offline Cássio SantosFriend
Messages: 4
Registered: November 2012
Junior Member
Ralph,

The problem is exactly that I can't specify these functions, because I can't use the type Set as a parameter or a return in a eCore operation. The following code would be the translation to OCLInEcore for my ocl functions, but they don't compile:
What I need to solve my problem is some kind of equivalence, between OCL collection dataTypes and eCore collection dataTypes

class Concept
{
   operation superrolePlus():Set(Role)
   {
     body: self.superrolePlusOnSet(self.superrole)
   }
   operation superrolePlusOnSet(rs:Set(Role)):Set(Role)
   {
     body: 
     if rs.superrole->exists(r|rs->excludes(r))
     then self.superrolePlusOnSet(rs->union(rs.superrole)->asSet())
     else rs->including(self)
     endif
   }
}


Thanks,
Re: Helper functions in OCL constraints [message #989061 is a reply to message #989011] Tue, 04 December 2012 13:41 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

your problem is that you use the wrong syntax to define the sets. You could try to open the meta model in the tree based editor and add the return type and parameters there. To get a collection just add the etype you want to have contained in the collection and set lower = 0 upper = -1. You do not need to add something like Collection<String> to use a collection in ecore.

Ralph
Re: Helper functions in OCL constraints [message #989129 is a reply to message #989061] Tue, 04 December 2012 17:48 Go to previous message
Cássio Santos is currently offline Cássio SantosFriend
Messages: 4
Registered: November 2012
Junior Member
Ralph,

Thanks a lot! With your information and a some adjusts in the sentences I was able to specify these functions.
If someone is passing through the same, here's my final specification for the functions. (Some names are a little bit diferent like Role = Concept, and superrolePlus = superconceptStar)
operation superconceptStar() : Concept[*]
{
    body: self.superconceptStarOnSet(self.superconcept());
}
operation superconceptStarOnSet(rs : Concept[*]) : Concept[*]
{
    body:
    if rs.superconcept()->exists(r : Concept | rs->excludes(r))
    then self.superconceptStarOnSet(rs->union(rs.superconcept())->asSet())
    else rs->including(self) 
    endif;
}


The invariant for no cicles is:
self.superconcept()->forAll(r|r.superconceptStar()->excludes(self))

Thanks a lot again Ralph!
Previous Topic:ModelingAssistant Popup for ShapeCompartments
Next Topic:Workaround for "Focus transfer copies values into text fields" bug?
Goto Forum:
  


Current Time: Fri Apr 19 22:00:11 GMT 2024

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

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

Back to the top