Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] How to iterate through the global UML model from inside a template
[Acceleo] How to iterate through the global UML model from inside a template [message #1051528] Sun, 28 April 2013 23:26 Go to next message
Spider 3000 is currently offline Spider 3000Friend
Messages: 1
Registered: April 2013
Junior Member
Hi!

I have a simple starting template, like this:

[template public main(aClass : Class)]
[comment @main/]
[aClass.generate()/]
[/template]


Now in the method generate() I want to also iterate through all the objects of the type "Comment" (and not just the ones linked to aClass). How would I do that?


Thank you very much for any help!

[Updated on: Mon, 29 April 2013 23:24]

Report message to a moderator

Re: [Acceleo] How to iterate through the global UML model from inside a template question [message #1052184 is a reply to message #1051528] Mon, 29 April 2013 19:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

That's what allInstances() allows you to do, if you're foolish enough
not to identify a much much more efficient algorithm.

Regards

Ed Willink


On 29/04/2013 03:53, Spider 3000 wrote:
> Hi!
>
> I have a simple starting template, like this:
>
> [template public main(aClass : Class)]
> [comment @main/]
> [aClass.generate()/]
> [/template]
>
> Now in the method generate() I want to also iterate through all the
> objects of the type "Comment" (and not just the ones linked to
> aClass). How would I do that?
>
>
> Thanks you very much for any help!
Re: [Acceleo] How to iterate through the global UML model from inside a template question [message #1053421 is a reply to message #1052184] Sun, 05 May 2013 10:17 Go to previous messageGo to next message
Mathias Colpaert is currently offline Mathias ColpaertFriend
Messages: 13
Registered: November 2012
Junior Member
Another classy reply from Ed.
Re: [Acceleo] How to iterate through the global UML model from inside a template question [message #1058264 is a reply to message #1053421] Mon, 13 May 2013 12:14 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

If you want to iterate on all the elements with the type Comment in your UML model, you can do something like this:
[template public main (aModel : Model)]
[comment @main/]
[for (aComment : Comment | aModel.eAllContents(Comment))]
// do something
[/for]
[/template]


You should use the root of the UML model (Model) as the entry point of your generator instead of class. If you really need to start from a class, you can use something like:
[myClass.ancestors(Model)->first()/]


You can find an Acceleo-based UML to Java generator on Github if you want to have a look at a complex Acceleo generator (it is open source). You can find some information about this generator on my blog here and there.

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Google+: +stephane.begaudeau
Blog: http://stephanebegaudeau.tumblr.com | Eclipse Java Development Tools Tips and Tricks
Previous Topic:M2T with Xtext2 and Xtend2
Next Topic: [acceleo] How to create file "Android Model" with EMF Eclipse
Goto Forum:
  


Current Time: Thu Apr 18 11:53:08 GMT 2024

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

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

Back to the top