|
Re: [Acceleo] OCL and Query utilisation [message #673300 is a reply to message #672239] |
Mon, 23 May 2011 07:34   |
|
Hi,
The Acceleo syntax is a superset of OCL, so you're probably using it whether you know it or not . Each of the "blue" colored areas in the template editor is basically an OCL expression.
That said, you can perfectly write Acceleo modules that are essentially composed of templates, never making use of any query. Queries can make the generation flow more readable by extracting some of the navigation or logic in small pieces of code. For example, if you have a template such as this one :
---------------
[template public generateClasses(ePackage : EPackage)]
[for (eClass : EClass | ePackage.eClasses->reject(class : EClass | class.abstract))]
public class [eClass.name.toUpperFirst()/] {
... class body ...
}
[/for]
[/template]
---------------
but you think you could use the logic of "get all classes that are not abstract" elsewhere, you could rewrite it like this :
---------------
[template public generateClasses(ePackage : EPackage)]
[for (eClass : EClass | concreteClasses(ePackage))]
public class [eClass.name.toUpperFirst()/] {
... class body ...
}
[/for]
[/template]
[query public concreteClasses(ePackage : EPackage) : Sequence(EClass) =
ePackage.eClasses->reject(class : EClass | class.abstract)
/]
---------------
so that you can use the "concreteClasses" query instead of copy/pasting the whole expression everywhere you need it.
Laurent Goubet
Obeo
|
|
|
|
|
Re: [Acceleo] OCL and Query utilisation [message #685843 is a reply to message #685464] |
Mon, 20 June 2011 11:03  |
|
stuart mackey wrote on Fri, 17 June 2011 16:50I was puzzled by this too as a still new user. I think however the main distinction is that templates only produce text whereas a query can return typed data for further processing.
So, for example, I don't think you can write a template to produce a filtered list of items to be used repeatedly from other templates. You'd have to use a query for that.
Can someone more experienced confirm?
Hi,
It is correct, templates are creating strings and queries can return elements of your metamodels and elements of the OCL language like a "Set" (OCL) of "Package" (UML) for example.
Regards,
Stephane Begaudeau, Obeo
--
Twitter: @sbegaudeau
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
|
|
|
Powered by
FUDForum. Page generated in 0.01977 seconds