[ATL] oclAsType [message #70149] |
Fri, 21 December 2007 04:59  |
Eclipse User |
|
|
|
Originally posted by: firstname.name.gmail.com
Hello,
I have to do some measures on uml profiles. One of the metric is to calculate,
for a given extended metaclass, the number its children (meta).
With the eclipse ocl console this query works as expected (context is a
ElementImport and importedElement is NamedElement)
self.importedElement.getModel().allOwnedElements()
->iterate(e:Element; childs:Set(Element)=Set{} |
if ((e.oclAsType(uml::Class).isAbstract=false)
and
e.oclAsType(uml::Class).allParents()->exists(p |
p.oclAsType(uml::Class).name='Relationship'))
then
childs->including(e)
else
childs
endif
)
With ATL I defined this helper (correctly called on a meta class)
def:numberOfNonAbstractChilds():Integer =
self.debug('this is the metaclass').getModel().debug('this is the metamodel').allOwnedElements()
->iterate(e; childs:Set(UML!Element)=Set{} |
if ((e.abstract=false) and e.allParents()->exists(p | p.name=self.name)) then
childs->including(e)
else
childs
endif)->size();
It fails. I get the message that feature 'isAbstract' (or abstract) as well as
'allParents()' doesn't exist. This expected since this feature doesn't belong to
this element, but fort its meta. This is why I use the tricky cast uml::Class in
OCL.
So my question is how can I do the same thing with ATL.
thanks a lot.
--
F. Lagarde
|
|
|
|
Re: [ATL] oclAsType [message #70311 is a reply to message #70271] |
Sat, 29 December 2007 16:31  |
Eclipse User |
|
|
|
Originally posted by: firstname.name.gmail.com
Le mercredi 26 décembre vers 17h "Frédéric" (Frédéric THOMAS) aurait apparemment
mentionné:
Frédéric> Hi françois, If I understand well you want to count all parents
Frédéric> of a UML metaclass.
thanks for your reply.
You are right that for this measurement, the better would be to deem my input
model as a model conforms to the ECORE metamodel, but the other (and main)
counts are to make on uml profiles, and so, I want to use uml as metamodel.
I finally found my error (and the workaround). Let's say that the context is a metaclass:
self.getModel().allOwnedElements()
->iterate(e; childs:Set(UML!Element)=Set{} |
if ((e.oclIsTypeOf(UML!Class) and (e.allParents()->includes(self))) then
childs->including(e)
else
childs
endif);
fails because every element belonging to the model (uml2 infrastructure) are not
of "the type" of UML!Class (even if I make sure the type of the element at
first). The point is that all of the clauses of the conjunction aree evaluated
even if the first one fails.
In my mind, I thought that the normal behavior was as for Java, i.e:, within a
conjunction, if the first clause is false, then the others are not evaluated
(order of the clauses has a consequence and may be used for optimization). This
the same with the Eclipse OCL.
The workaround that I found is the following: (don't know if it is better, or
may help someone...)
self.getModel().allOwnedElements()
->select(e | (e.oclIsTypeOf(UML!Class))
->iterate(e; childs:Set(UML!Element)=Set{} |
if (e.allParents()->includes(self)) then
childs->including(e)
else
childs
endif);
thanks and happy new year!
--
François
|
|
|
Powered by
FUDForum. Page generated in 0.09027 seconds