Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Codebeautifier and conditional codegeneration
[Acceleo] Codebeautifier and conditional codegeneration [message #727057] Tue, 20 September 2011 10:13 Go to next message
st oehm is currently offline st oehmFriend
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 #727156 is a reply to message #727057] Tue, 20 September 2011 14:40 Go to previous messageGo to next message
Leonardo Kenji Shikida is currently offline Leonardo Kenji ShikidaFriend
Messages: 37
Registered: July 2009
Member
Hi

there are several java beautifiers out there. If you´re running from inside eclipse, you can even try to start it´s beautifier via JDT.

http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_api_codeformatter.htm

there must be a way to apply the code formatter to all the files from inside a project programatically, because when you right-click on a package, you can call "format" and it´s applied to everything under the selected node.

about conditional code generation, it depends on what is the condition. If your condition is just a value from your model, you can just write a template like this

[template public generateElement(aMyObject : MyObject)]
[comment @main/]
[if (aMyObject.condition = Condition::XXX)]
[callAnotherTemplate(aMyObject)/]
[/if]
[/template]

but if it´s something more complex, you can write a "service", which maps to a java method that can return a boolean.

http://wiki.eclipse.org/Acceleo/FAQ#How_to_use_a_Java_service_in_Acceleo

Best regards

Kenji
Re: [Acceleo] Codebeautifier and conditional codegeneration [message #727189 is a reply to message #727156] Tue, 20 September 2011 15:22 Go to previous messageGo to next message
st oehm is currently offline st oehmFriend
Messages: 79
Registered: October 2009
Member
thanks a lot for this informations. i didn't think of this workarounds, because in other frameworks (for example XPand) there are direct ways to do this

best regards
Re: [Acceleo] Codebeautifier and conditional codegeneration [message #727421 is a reply to message #727189] Wed, 21 September 2011 09:12 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

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
Previous Topic:[acceleo] check for already generated java code
Next Topic:[acceleo] how to call a template method from inside a java method
Goto Forum:
  


Current Time: Thu Apr 18 05:59:59 GMT 2024

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

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

Back to the top