Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [acceleo] Good practice, implicit variable and constant queries
[acceleo] Good practice, implicit variable and constant queries [message #731154] Fri, 30 September 2011 06:57 Go to next message
Marc Missing name is currently offline Marc Missing nameFriend
Messages: 38
Registered: March 2011
Member
Hi (again),

In my templates, I want to set some values to constants (like constant prefixes, paths, ...). Currently, I'm using queries with no argument like

[query public bla() : String = 'toto' /]


Then, I've read that it's a good idea to have a parameter, even when it's not used:

[query public bla(anything: OclAny) : String = 'toto' /]


And this still works. I guess because when I call it with
[bla()/]
some implicit variable is used.

Now, the Good Practice says it's a bad idea to call queries like that and an explicit context should always be used. So, I ended up adding an explicit context for my calls, even if they are not used. And I find it misleading, as when reading the code, you can think that the bla() query will really use the context to compute its value, which is not the case.

I have 2 questions:
- in this particular case (constant query), is it safe to use bla() instead of x.bla() ?

- is there a cleaner way to handle constant values in templates ?

Thanks,
Marc
Re: [acceleo] Good practice, implicit variable and constant queries [message #731178 is a reply to message #731154] Fri, 30 September 2011 07:58 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Marc,

Queries without arguments are not recommended if you wish to make use of the traceability, as their traceability information will not be attached to anything (no argument = no context for the traceability). A "dummy" argument only serves that purpose.

Yet queries are not the recommended practice to define constants. What you should use here are properties files. Properties files for Acceleo are explainfed in the Acceleo User Guide, or Stéphane had described their use on his blog.

Laurent Goubet
Obeo

[edit : just realized that we have not mentionned this in the Acceleo best practices... this will have to change Smile]

[Updated on: Fri, 30 September 2011 08:02]

Report message to a moderator

Re: [acceleo] Good practice, implicit variable and constant queries [message #731818 is a reply to message #731178] Mon, 03 October 2011 08:21 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Marc,

Laurent gave you the link to the Acceleo 3.0.x user guide, but you can also have a look at the Acceleo 3.1.x user guide here. If have updated the best practices guide to indicate that properties files should be used for constants. If have also updated the Acceleo properties files guide in which you can find all the available ways to use properties files.

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Google+: stephane.begaudeau
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
Previous Topic:modul to filter classes
Next Topic:org.eclipse.xtend.typesystem.uml2 as plugin-depency
Goto Forum:
  


Current Time: Thu Apr 18 09:39:46 GMT 2024

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

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

Back to the top