Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 08:18 Go to next message
Marc Gil is currently offline Marc GilFriend
Messages: 190
Registered: July 2009
Location: Valencia, Spain
Senior Member
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 09:20 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
.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 09:36 Go to previous messageGo to next message
Marc Gil is currently offline Marc GilFriend
Messages: 190
Registered: July 2009
Location: Valencia, Spain
Senior Member
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 09:51 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
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 11:04 Go to previous message
Marc Gil is currently offline Marc GilFriend
Messages: 190
Registered: July 2009
Location: Valencia, Spain
Senior Member
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: Mon Jun 17 07:49:33 GMT 2019

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

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

Back to the top