Skip to main content



      Home
Home » Archived » M2M (model-to-model transformation) » A helper with a "Type element" parameter
icon5.gif  A helper with a "Type element" parameter [message #631353] Thu, 07 October 2010 04:18 Go to next message
Eclipse UserFriend
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 #631363 is a reply to message #631353] Thu, 07 October 2010 05:20 Go to previous messageGo to next message
Eclipse UserFriend
.oclIsTypeOf(type)
will work just fine
Re: A helper with a "Type element" parameter [message #631364 is a reply to message #631363] Thu, 07 October 2010 05:36 Go to previous messageGo to next message
Eclipse UserFriend
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 #631369 is a reply to message #631353] Thu, 07 October 2010 05:51 Go to previous messageGo to next message
Eclipse UserFriend
You can't use .eAllContents() but you can re-code it using .eContents() which is available in ATL transformations.
Re: A helper with a "Type element" parameter [message #631380 is a reply to message #631369] Thu, 07 October 2010 07:04 Go to previous message
Eclipse UserFriend
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')
Previous Topic:[ATL] How can i use a XML injector in a build in ATL 3.1 ?
Next Topic:[ATL] Bug in stack handling in 3.1.1?
Goto Forum:
  


Current Time: Wed Jul 23 14:32:11 EDT 2025

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

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

Back to the top