Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community Forums[Acceleo] OCL and Query utilisation
https://www.eclipse.org/forums/index.php/mv/msg/209629/672239/#msg_672239
I'm using Acceleo 3, and i have to say it works very well, I can do everythings i need for the moment.
I'm just here because I see lot of things about OCL and Query in Acceleo, and i'm not using it at all (except auto-generated queries for some services), so i think i'm missing somethings.
I may be wrong but it seems that all the java services i use to extract informations from my model could also be written with a ocl query, is it a better way ?
Will I, sooner or later, face problems that only queries can solve ?
I've not any problem right now, but my project is growing and I want to avoid it to grow in the wrong way.
Thanks !]]>Valerian Merkling2011-05-20T12:31:24-00:00Re: [Acceleo] OCL and Query utilisation
https://www.eclipse.org/forums/index.php/mv/msg/209629/673300/#msg_673300
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]
so that you can use the "concreteClasses" query instead of copy/pasting the whole expression everywhere you need it.
Laurent Goubet
Obeo]]>Laurent Goubet2011-05-23T07:34:01-00:00Re: [Acceleo] OCL and Query utilisation
https://www.eclipse.org/forums/index.php/mv/msg/209629/673415/#msg_673415
Valerian Merkling2011-05-23T15:00:39-00:00Re: [Acceleo] OCL and Query utilisation
https://www.eclipse.org/forums/index.php/mv/msg/209629/685464/#msg_685464
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?]]>stuart mackey2011-06-17T14:50:46-00:00Re: [Acceleo] OCL and Query utilisation
https://www.eclipse.org/forums/index.php/mv/msg/209629/685843/#msg_685843
stuart mackey wrote on Fri, 17 June 2011 16:50
I 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.