简体   繁体   English

在Acceleo中包装Java函数(在Eclipse中)

[英]Wrap java function in Acceleo (in Eclipse)

I have to wrap a java function inside an Acceleo File, is there anyone that can help me? 我必须在Acceleo File中包装一个Java函数,有人可以帮助我吗?

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. 从Acceleo调用Java服务的最简单方法是使用《用户指南》(您发现的是help.eclipse.org,但使用“用户指南”而不是“ Android教程”)中描述的功能来创建“ Java服务包装器”从Java文件中获取。 This automatically creates the Acceleo queries that will invoke Java code for you. 这将自动创建Acceleo查询,该查询将为您调用Java代码。

However, you cannot call Java code from Acceleo without having Java classes. 但是,如果没有Java类,则无法从Acceleo调用Java代码。 "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. “ mtl”文件仅允许Acceleo代码,尽管您可以从Acceleo调用Java方法,但是它们必须位于自己的“ java”类文件中。 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. 您还可以调用您不拥有的Java代码,只要您的Acceleo项目取决于您要从中调用代码的库即可。 For example, the following Acceleo query would call the method org.eclipse.emf.ecore.util.EcoreUtil.getID(EObject) on the given EClass : 例如,以下Acceleo查询将在给定的EClass上调用org.eclipse.emf.ecore.util.EcoreUtil.getID(EObject)方法:

[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). (现在您了解了为什么让Acceleo为您生成这些查询更容易: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. 我们确实希望使对Java服务的支持更易于使用,但是目前这仅在我们的愿望清单上,尚无计划。

Do not hesitate to look on the wiki ( http://wiki.eclipse.org/Acceleo ) for information, and to edit it if we're missing something :). 不要犹豫,在Wiki( http://wiki.eclipse.org/Acceleo )上查找信息,如果我们缺少某些内容,请进行编辑:)。

PS: sorry for the lack of hyperlinks, my stackoverflow account is still a little young. PS:对不起,因为没有超链接,我的stackoverflow帐户还很年轻。

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. 为了完成Kellindil的回答,我在Acceleo的FAQ中添加了一个新条目,其中包括使用Java服务的屏幕截图。

How to use a Java service in Acceleo 3 如何在Acceleo 3中使用Java服务

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. eclipse帮助页面上的此页面包含一个教程,在我看来,好像它们在模型文件中包含Java代码一样。 Hope it helps. 希望能帮助到你。

Acceleo Code Generation 加速代码生成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM