[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.mdt.ocl] Re: How to check the types of containment?

Hi, Gilbert,

See some replies in-line, below.

cW


On Wed, 2009-09-16 at 19:22 +0200, Gilbert Mirenque wrote:
Hi Christian,
only for completeness...

> Content assist may not show you the "closure" iterator because it is not
> OMG-standard OCL.  However, it should parse.
...this result comes:
Usage of non-standard "closure" iterator

Can you please explain a little bit this _expression_:

self.exportedEvents->forAll(ev|
	ev->closure(eContainer())->includes(self)
)

What this is intended to do is to use the closure() iterator to compute the set of container elements (recursively) of the element and check that "self" is in it.  This is one way of testing whether an object is contained in self's subtree; another would be to iterate that sub-tree looking for "ev."


Especially closure(eContainer())does what exactly? Does it return all
elements contain ev? Then it should only be one and self should be
included in this closure, right. Do I understand this correctly?

Almost.  The closure iterator computes the transitive closure of the body _expression_ evaluated on the elements of the source collection (in this case, the singleton set "Set{ev}").  So, it finds the eContainer() of ev, and the eContainer() of that, etc. until it finds no more new eContainers.


Just for curiosity. The following expressions parses correctly

self.exportedEvents ->forAll(ev| 	
	self.eContents()
	->select(x|
		x.oclIsTypeOf(CRUISeMetaModel::Event))
	->includes(ev)
)

But I wonder about self.eContents(). Is the semantic like I used it here?

I don't understand your question.  One point to note is that eContents() is not recursive:  it computes only the immediately contained elements.  The problem that the closure-of-eContainer approach addresses is that EObject does not provide a variant of eAllContents() that yields a collection; the tree iterator result is useless in OCL.


best regards,
Gilbert