Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand2] Generating multiple files with one Xpand "model tree travers"
[Xpand2] Generating multiple files with one Xpand "model tree travers" [message #1610121] Tue, 10 February 2015 15:18 Go to next message
Bastian Mohrmann is currently offline Bastian MohrmannFriend
Messages: 12
Registered: November 2014
Junior Member
Hello dear eclipse community,

right now i am working on an Xpand model-to-text project.
I already got familiar with the Xpand language and my .mwe workflow already generates some code. I created several templates which are more or less built up modular in order to ease future extensions.

What i want to do now is to generate a file where all the imports for the generated implementation files are stored. So when i traverse the "model tree" i want to create on the one hand the necessary implementation files and on the other hand all the necessary imports, but in a seperate file... Is there some good strategy for this purpose? I thought about the following:

1. Create a second seperate template that traverses the model tree and that collects all the imports. The disadvantage here is that the model tree is traversed two times and that i will have a lot of redundant code in seperate templates.

2. I thought if the "AROUND" aspect can help me somehow with that?

3. A global list in which the imports are stored one by one and from which the import file is generated in the end (i am not even sure if that is possible in XPand)

Thanks for your help in advance,
Greetings,
Bastian Mohrmann
Re: [Xpand2] Generating multiple files with one Xpand "model tree travers" [message #1610436 is a reply to message #1610121] Tue, 10 February 2015 20:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Xpand has been superseded by Xtend, which is a kind of Java++.

String templates provide the necessary capabilities for M2T, but are
such a minor part of the language that you would not reralize from the
overviews that Xtend is good for M2T.

Since Xtend gives you the full capabilities of Java there is a much
easier solution; you create your main body while accumulating imports in
a Set<String>. When finished you can generate multiple outputs or a
concatenated output.

If you are not comfortable with the slight differences from Java, you
may prefer to write the M2T in a *.xtend file that extends a *.java that
contains your real business logic.

Regards

Ed Willink

On 10/02/2015 15:18, Bastian Mohrmann wrote:
> Hello dear eclipse community,
>
> right now i am working on an Xpand model-to-text project.
> I already got familiar with the Xpand language and my .mwe workflow
> already generates some code. I created several templates which are more
> or less built up modular in order to ease future extensions.
>
> What i want to do now is to generate a file where all the imports for
> the generated implementation files are stored. So when i traverse the
> "model tree" i want to create on the one hand the necessary
> implementation files and on the other hand all the necessary imports,
> but in a seperate file... Is there some good strategy for this purpose?
> I thought about the following:
>
> 1. Create a second seperate template that traverses the model tree and
> that collects all the imports. The disadvantage here is that the model
> tree is traversed two times and that i will have a lot of redundant code
> in seperate templates.
>
> 2. I thought if the "AROUND" aspect can help me somehow with that?
> 3. A global list in which the imports are stored one by one and from
> which the import file is generated in the end (i am not even sure if
> that is possible in XPand)
>
> Thanks for your help in advance,
> Greetings,
> Bastian Mohrmann
Re: [Xpand2] Generating multiple files with one Xpand "model tree travers" [message #1611251 is a reply to message #1610121] Wed, 11 February 2015 08:43 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Xpand is still maintained and used by some projects, although I would recommend to use Xtend for new projects also. However, this was not the question.

If you want to achieve something like this, use the "globalvar" extensions from stdlib to store such a list. Make sure that it is initiated before the first import is collected and that it is freed after writing your imports file.

See "stdlib" documentation for some details how to use it.


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: [Xpand2] Generating multiple files with one Xpand &quot;model tree travers&quot; [message #1611535 is a reply to message #1610436] Wed, 11 February 2015 12:33 Go to previous message
Bastian Mohrmann is currently offline Bastian MohrmannFriend
Messages: 12
Registered: November 2014
Junior Member
Thank you.

I started with Xtend this morning... A big advantage for me is that i can implement everything in java now, despite one xtend file. Now i follow the strategy to create a seperate List<String> for each file i want to create together with the name, dir and extension of the file. After the model tree is traversed, all files that were created are generated with the IFileSystemAccess class.
Unfortunately, i can throw away my Xpand project now Smile but i think its better this way.

Thanks again,
Regards,
Bastian Mohrmann
Previous Topic:Acceleo - Building error when importing module - emtl not found unless it actually exists
Next Topic:Acceleo online: edit templates in the browser
Goto Forum:
  


Current Time: Mon May 06 06:52:20 GMT 2024

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

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

Back to the top