Wrap java function in Acceleo (in Eclipse)
I have to wrap a java function inside an Acceleo File, is there anyone that ca开发者_开发百科n help me?
Thank you
The easiest way to call Java Services from Acceleo is to use the facility described in the User Guide (help.eclipse.org as you found out, but "User Guide" instead of "Android tutorial") to create a "Java services wrapper" from a Java file. This automatically creates the Acceleo queries that will invoke Java code for you.
However, you cannot call Java code from Acceleo without having Java classes. "mtl" files only allow for Acceleo code, and though you can call Java methods from Acceleo, they have to be located in their own "java" class files. You can also call java code that you do not own, as long as your Acceleo project depends on the library you want to call code from. For example, the following Acceleo query would call the method org.eclipse.emf.ecore.util.EcoreUtil.getID(EObject)
on the given EClass :
[query public getURI(eClass : EClass) : String = invoke('org.eclipse.emf.ecore.util.EcoreUtil', 'getID(org.eclipse.emf.ecore.EObject)', Sequence{eClass})/]
(and now you see why it is easier to let Acceleo generate these queries for you :p).
We do expect to make the support for Java services easier to use, but for now this is only on our wish list and not planned.
Do not hesitate to look on the wiki ( http://wiki.eclipse.org/Acceleo ) for information, and to edit it if we're missing something :).
PS: sorry for the lack of hyperlinks, my stackoverflow account is still a little young.
In order to complete the answer from Kellindil, I've added a new entry in the FAQ of Acceleo with a screenshot of the use of a Java service.
How to use a Java service in Acceleo 3
This page from the eclipse help pages contains a tutorial and it looks to me as if they include java code in the model files. Hope it helps.
Acceleo Code Generation
精彩评论