[Acceleo] Codebeautifier and conditional codegeneration [message #727057] |
Tue, 20 September 2011 10:13 |
st oehm Messages: 79 Registered: October 2009 |
Member |
|
|
hello,
i just have two simple questions to acceleo:
is there a code beautifier available for the generated code, or an easy possibility you can get well formatted code?
is there a way for conditional codegeneration? i think of a possibility to break codegeneration and give out an error if some condition is violated?
if there is not something like this in the actual version, is this planed for the future?
best regards
stoehm
[Updated on: Tue, 20 September 2011 10:21] Report message to a moderator
|
|
|
|
|
Re: [Acceleo] Codebeautifier and conditional codegeneration [message #727421 is a reply to message #727189] |
Wed, 21 September 2011 09:12 |
|
Hi
We recommend that the code generated should be formatted directly within the templates. You can use the JDT formatter after the generation if you wish of course but it will impact traceability informations.
And for the conditions, you have several options.
1- you can use "if" blocks with Java services as shown by Kenji
2- in Acceleo 3.1.1 (you can do it in Acceleo 3.0.x and 3.1.0 too but it's a bit more complex), you can also parameterized your generation thanks to properties files with, for example, a default value in your generator and if your users creates a properties files with other settings it can (you decide) overwrite your default settings.
It could look like this:
[template myTemplate(var : Mytype) ? (getProperty('genType') <> 'mysql' and getProperty('genType') <> 'mongodb' )]
// FIXME invalid genType in the properties file
[/template]
[template myTemplate(var : Mytype) ? (getProperty('genType') = 'mysql')]
// My SQL code
[/template]
[template myTemplate(var : Mytype) ? (getProperty('genType') = 'mongoDB')]
// MongoDB code
[/template]
In your default properties file, you can set "genType" to "mysql" and your users can change this value in their properties files. The guard on the template will make sure that it is executed only if the condition is true.
Regards,
Stephane Begaudeau, Obeo
--
Twitter: @sbegaudeau
Google+: stephane.begaudeau
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
|
|
|
Powered by
FUDForum. Page generated in 0.03478 seconds