在 Xtext 语法中集成 OCL 类型时出现问题

发布于 2024-09-19 02:17:53 字数 1944 浏览 10 评论 0原文

我正在开发一个语法(Xtext 项目),我想在其中重用 OCL 类型。通常,您在 Xtext 中使用 import 语句引用现有类型,例如

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

,已经有一个示例 Xtext 项目 (CompleteOCL),它将 OCL 类型集成到语法中。不幸的是,该项目在其导入语句中引用了本地插件,例如,

import "platform:/resource/org.eclipse.ocl.examples.xtext.base/model/BaseCST.ecore" as base

因此 Manifest.MF 文件中没有定义依赖项。如果我想在我的语法中重用 OCL 类型,我必须编写,例如

import "http://www.eclipse.org/ocl/3.0.0/BaseCST" as base

我添加了 org.eclipse.ocl.examples.xtext.base 依赖项,并且可以在我的语法中编写引用 (OCL) BaseCST 类型的规则。如果我尝试生成 Xtext artifcats,我会收到以下错误:

     ... 3 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:54)
    ... 36 more
Caused by: java.lang.IllegalStateException: Problem parsing 'classpath:/org/xtext/example/mydsl/MyDsl.xtext':[XtextLinkingDiagnostic: null:5 Couldn't resolve reference to EPackage 'http://www.eclipse.org/ocl/3.0.0/BaseCST'.]
    at org.eclipse.xtext.generator.LanguageConfig.setUri(LanguageConfig.java:112)
    ... 41 more

那么我可能遗漏了一些东西?这个问题很容易重现。创建一个新的 Xtext 项目,添加依赖项,编辑语法并添加最后一个导入语句(“import "http://...”)并尝试生成 Xtext 工件。欢迎任何想法!

提前致谢!< br> Michael

编辑:为了使用语法,您必须在 MWE2 工作流程(请参阅 Xtext 文档(版本 1.0.1)的第 3.2.2.2 节)中引用 ecore 模型的相应 genmodel 文件,例如

fragment = org.eclipse.xtext.generator.ecore.EcoreGeneratorFragement {
  referencedGenModels = "platform:/plugins/org.eclipse.ocl.examples.xtext.base/model/BaseCST.genmodel
} 

尽管如此,它仍然不为我工作。

I'm working on a grammar (Xtext project) where I want to reuse OCL types. Usually you refer in Xtext to existing types with an import statement, e.g.

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

There is already an example Xtext project (CompleteOCL) which integrates OCL types in a grammar. Unfortunately the project refers in its import statements to local plugins, e.g.

import "platform:/resource/org.eclipse.ocl.examples.xtext.base/model/BaseCST.ecore" as base

So there are no dependencies defined in the Manifest.MF file. If I want to reuse OCL types in my grammar I have to write for example

import "http://www.eclipse.org/ocl/3.0.0/BaseCST" as base

I've added the org.eclipse.ocl.examples.xtext.base dependency and can write rules in my grammar which refer to (OCL) BaseCST types. If I try to generate the Xtext artifcats I get the following error:

     ... 3 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:54)
    ... 36 more
Caused by: java.lang.IllegalStateException: Problem parsing 'classpath:/org/xtext/example/mydsl/MyDsl.xtext':[XtextLinkingDiagnostic: null:5 Couldn't resolve reference to EPackage 'http://www.eclipse.org/ocl/3.0.0/BaseCST'.]
    at org.eclipse.xtext.generator.LanguageConfig.setUri(LanguageConfig.java:112)
    ... 41 more

So probably I'missing something? The problem is quite easy to reproduce. Create a new Xtext project, add the dependency, edit the grammar and add the last import statement ("import "http://...") and try to generate the Xtext artifacts. Any ideas are welcome!

Thanks in advance!
Michael

EDIT: In order to use a grammar you have to refer in your MWE2 workflow (see section 3.2.2.2 of the the Xtext documentation (version 1.0.1)) to the corresponding genmodel file of the ecore model, for example

fragment = org.eclipse.xtext.generator.ecore.EcoreGeneratorFragement {
  referencedGenModels = "platform:/plugins/org.eclipse.ocl.examples.xtext.base/model/BaseCST.genmodel
} 

Nevertheless it's still not working for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白首有我共你 2024-09-26 02:17:54

CompleteOCL 项目是包含 Xtext 项目的 Eclipse 工作区的一部分吗?如果是这样,您可以尝试使用您提到的平台 URI 来引用 Ecore 文件:

import "platform:/resource/org.eclipse.ocl.examples.xtext.base/model/BaseCST.ecore" as base

而不是

import "http://www.eclipse.org/ocl/3.0.0/BaseCST" as base

If the CompleteOCL 项目的捆绑包是您的 Eclipse 目标平台的一部分(例如,您的 Eclipse 安装的一部分),那么错误

Couldn't resolve reference to EPackage 'http://www.eclipse.org/ocl/3.0.0/BaseCST'

恕我直言表明该捆绑包提供该EPackage未激活。

Is the CompleteOCL project part of the Eclipse workspace that contains your Xtext project? If so you could try to reference the Ecore file using the platform URI you mentioned:

import "platform:/resource/org.eclipse.ocl.examples.xtext.base/model/BaseCST.ecore" as base

instead of

import "http://www.eclipse.org/ocl/3.0.0/BaseCST" as base

If the CompleteOCL project's bundles are part of your Eclipse target platform (e.g., part of your Eclipse installation), then the

Couldn't resolve reference to EPackage 'http://www.eclipse.org/ocl/3.0.0/BaseCST'

error imho indicates that the bundle providing this EPackage is not activated.

孤檠 2024-09-26 02:17:54

最好的办法应该是在 Eclipse 中安装该语法。
导入您的 CompleteOCL 项目。然后右键单击它>导出>可部署的插件和片段>选中CompleteOCL项目>然后单击单选按钮安装到主机>单击完成并重新启动Eclipse。

现在您应该能够将导入作为 import "http://www.eclipse.org/ocl/3.0.0/BaseCST" as base

问候,

Xavier

Your best shot should be to install that grammar within your eclipse.
Import your CompleteOCL project. Then right click on it>export>deployable plug-ins and fragments>check CompleteOCL project>and click the radio button install into host>Click finish and restart Eclipse.

Now your should be able to make your import as import "http://www.eclipse.org/ocl/3.0.0/BaseCST" as base

Regards,

Xavier

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文