A helper with a "Type element" parameter [message #631353] |
Thu, 07 October 2010 08:18 |
|
Hi!
My goal is to get all the elements of certain type contained into an element. Its possible to create a helper that is applied to a type of element, and I pass as argument the type of elements I want to get? Something like that:
helper context metamodel!element def : getContainedTypedElements(type : metamodel!elementType) : Sequence(metamodel!elementType) = ...;
The parameter is not an element instance, but a MetaClass.
Thanks!
|
|
|
|
Re: A helper with a "Type element" parameter [message #631364 is a reply to message #631363] |
Thu, 07 October 2010 09:36 |
|
Well, sorry, perhaps I have not explain the problem correctly. I want to iterate the ALL contents of an element, looking for elements of certain Type.
Can I iterate a Tree in ATL? If I can do it, I can iterate the eAllContents() of an eObject and make my own checks in order to retrieve the elements I want to get.
Thanks Sylvain.
|
|
|
|
Re: A helper with a "Type element" parameter [message #631380 is a reply to message #631369] |
Thu, 07 October 2010 11:04 |
|
Thanks Sylvain!!!
I have coded the eAllContents indicating the type of the elements you want to retrieve. Perhaps it's usefull for anybody, so I Copy&Paste the ATL code here.
helper def: contentList : Sequence(metamodel!ReturnedElementType) = Sequence {};
helper context metamodel!ElementType def : contentsOfType(type : String) : Sequence (metamodel!ReturnedElementType) =
if self.eContents().notEmpty() then
thisModule.contentList->
union(self.eContents()->select(e | e.eClass().getName() = type))->
union(self.eContents()->iterate(e; seq : Sequence (sketcher!SketcherElement) = Sequence {} |
seq.union(e.contentsOfType(type))))
else
thisModule.contentList
endif;
The call is something like that:
element.contentsOfType('metamodel!ReturnedElementType')
|
|
|
Powered by
FUDForum. Page generated in 0.03584 seconds