|Re: [Acceleo] Accessing external variables from templates [message #533082 is a reply to message #532205]
||Wed, 12 May 2010 08:10
|| Laurent Goubet
Registered: July 2009
This is a multi-part message in MIME format.|
Content-Type: text/plain; charset=UTF-8; format=flowed
You can define Acceleo templates with more than one argument ("[template
public templateName(arg0 : type, arg1 : type, arg2 : type, ...)]").
Nothing prevents you from passing arguments over to the generation
template ... though if you use the generated "main" method, it only
takes an array of Strings as parameter, in turn your arguments can only
be of type "String". The first String in the array has to be the path to
the model (and this is the model we'll iterate over to find the _first_
argument of the called template), the second String is the folder we'll
use as the root of the generated files' paths, any subsequent String
will be passed on to the called template as the second (and subsequent)
If you wish for more complex types as arguments of your generation
templates -keep in mind you can only use "model" element (elements
defined in a metamodel or instances of those)-, you'll have to mimic the
behavior of the generated "main" method and call the "doGenerate" yourself.
> I am writin mtl generation templates and I would like to access external
> variables to customize my generation.
> To make things clearer :
> I created an Eclipse wizard which aims at creating a custom java
> project. The project architecture is defined by the user within the
> wizard (package name..).
> When I click finish in the end of the wizard, I launch the generation
> template (by calling the main method of the java file associated to the
> mtl template).
> I would like to pass arguments to the mtl template, for example to
> generate files in the package defined in the wizard.
> Is there a way to achieve this ?
> Thanks in advance.
Content-Type: text/x-vcard; charset=utf-8;
Powered by FUDForum
. Page generated in 0.02734 seconds