Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] oclAsType
[ATL] oclAsType [message #70149] Fri, 21 December 2007 09:59 Go to next message
Eclipse UserFriend
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 #70271 is a reply to message #70149] Wed, 26 December 2007 16:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: frederic.thomas.cea.fr

Hi françois,

If I understand well you want to count all parents of a UML metaclass.
For example, you want to count how many UML metaclasses inherit from the
UML!Class metaclass. In such case, UML is a model conformed to the ECORE
metamodel. You have to write a query on ECORE elements. This a little
example of such query:

module essai; -- Module Template
create OUT : ECORE from IN : ECORE;

helper context ECORE!EClass def: numberOfNonAbstractChilds():Integer =
self.debug('this is the uml
metaclass').ePackage.eClassifiers->select(e|e.oclIsKindOf(ECORE!EClass)).debug('Element')
->iterate(e; childs:Set(ECORE!EClass)=Set{} |
if ((e.abstract=false) and e.eAllSuperTypes->includes(self)) then
childs->including(e)
else
childs
endif)->size();

entrypoint rule count() {
do{
ECORE!EClass->allInstancesFrom('IN')->select(e|e.name =
'Class')->collect(e|e.numberOfNonAbstractChilds().debug('Result'));
}
}

Fred
Re: [ATL] oclAsType [message #70311 is a reply to message #70271] Sat, 29 December 2007 21:31 Go to previous message
Eclipse UserFriend
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
Previous Topic:[ATL]Is there any way to execute a ATL file using java code
Next Topic:[ATL] Strange behavior when overriding called rule or lazy rule
Goto Forum:
  


Current Time: Sat Apr 27 00:14:07 GMT 2024

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

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

Back to the top