Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] OCL and Query utilisation
icon14.gif  [Acceleo] OCL and Query utilisation [message #672239] Fri, 20 May 2011 12:31 Go to next message
Valerian Merkling is currently offline Valerian MerklingFriend
Messages: 71
Registered: May 2011
Member
Hi !

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 !
Re: [Acceleo] OCL and Query utilisation [message #673300 is a reply to message #672239] Mon, 23 May 2011 07:34 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

The Acceleo syntax is a superset of OCL, so you're probably using it whether you know it or not Smile. 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 #673415 is a reply to message #673300] Mon, 23 May 2011 15:00 Go to previous messageGo to next message
Valerian Merkling is currently offline Valerian MerklingFriend
Messages: 71
Registered: May 2011
Member
Ok thanks, now i can better understand how it works.

[Updated on: Wed, 25 May 2011 15:29]

Report message to a moderator

Re: [Acceleo] OCL and Query utilisation [message #685464 is a reply to message #672239] Fri, 17 June 2011 14:50 Go to previous messageGo to next message
stuart mackey is currently offline stuart mackeyFriend
Messages: 7
Registered: July 2009
Junior Member
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?
Re: [Acceleo] OCL and Query utilisation [message #685843 is a reply to message #685464] Mon, 20 June 2011 11:03 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

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.


Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
Previous Topic:[ACCELEO] Associations and attributes
Next Topic:Acceleo 7June 2011 Release Help (version 3.1)
Goto Forum:
  


Current Time: Fri Mar 29 07:39:48 GMT 2024

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

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

Back to the top