如何在 xtext 项目之外使用 xtext 推断的 JVM 模型? [英] How to use xtext inferred JVM model outside of xtext project?

查看:22
本文介绍了如何在 xtext 项目之外使用 xtext 推断的 JVM 模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xtext 文档 (http://www.eclipse.org/Xtext/documentation.html#_17) 的 推断 JVM 模型 部分中,它首先说:在许多情况下,您会希望您的 DSL 概念可用作 Java 元素.例如,一个实体将成为一个 Java 类并且应该可以这样使用".

In the Inferring a JVM Model section of the Xtext documentation (http://www.eclipse.org/Xtext/documentation.html#_17) it starts by saying: "In many cases, you will want your DSLs concepts to be usable as Java elements. E.g. an Entity will become a Java class and should be usable as such".

在上面的示例中,我如何使用生成的实体类 outside 的 xbase,即在与 xtext 不同的项目中的实际 Java 代码中?

In the example above, how can I use the generated Entity class outside of xbase, i.e. in real Java code in a different project to the xtext one?

我本质上问的是,由模型 Inferrer 创建的 Java 类是否实际上可以用作真正的 Java 类,这些类可以在完全不同的项目中调用它们的方法并从 Java 代码访问字段,如果是这样如何做到这一点?

What I am essentially asking is if the Java classes created my by the model Inferrer can actually be used as real java classes, which can have their methods called and fields accessed from java code, in an altogether different project, and if so how this can be done?

我浏览文档让我担心生成的Java 类"只是 Xbase 类型,只是 xtext 上下文中的引用,因此不是真正的 Java 类...

My going through the documentation has lead me to fear that the generated "Java classes" are only Xbase types, only referenceabe in an xtext context, and are not therefore real java classes...

推荐答案

Xbase 编译器可以将所有 Xbase 表达式编译为普通 Java 代码,可在任何有 Java 代码的地方使用.

The Xbase compiler can compile all Xbase expressions to plain Java code usable everywhere where Java codes are available.

如果您将自己的元素添加到语言中,则必须扩展生成器以支持这些元素 - 为此,您需要定义自己的 JVMModelInferrer.

If you add your own elements to the language, you have to extend the generator to also support these elements - for this reason you define your own JVMModelInferrer.

基本的 Xtext 编译器然后执行 JVMModelInferrer,计算可能(或可能不)包含 Xbase 表达式的 JVM 模型;然后这个 JVM 模型可以生成为 Java 可编译(因此 Java 可重用)代码.

The basic Xtext compiler then executes the JVMModelInferrer, calculates the JVM model that might (or might not) contain Xbase expressions as well; then this JVM model can be generated into a Java-compilable (thus Java-reusable) code.

如果您想测试此功能,只需生成 Xtext 域模型示例(可从 Xtext/Examples 类别中的新建...向导获得),并评估结果:当您编辑域模型时,Xtext 会自动生成可用的 Java 代码(如果设置了所需的依赖项).

If you want to test this functionality, simply generate the Xtext Domain Model example (available from the New... wizards in Xtext/Examples category), and evaluate the results: when you edit your domain model, Xtext automatically generates the usable Java code (if the required dependencies are set).

这篇关于如何在 xtext 项目之外使用 xtext 推断的 JVM 模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆