【问题标题】:How to generate code from ecore model with OCL expressions in the separate file?如何使用单独文件中的 OCL 表达式从 ecore 模型生成代码?
【发布时间】:2020-07-19 18:16:33
【问题描述】:

我正在使用 Eclipse 插件来处理 OCL。我有一个包含一些操作和派生属性的 Ecore 模型,我还有一个单独的 OCL 文件,其中包含表达式。我制作了一个genmodel文件并添加了:

<genAnnotations source="http://www.eclipse.org/OCL/GenModel">
    <details key="Use Delegates" value="false"/>
</genAnnotations>

我还检查了嵌入在 ecore 模型中的 OCL 的首选项实现以生成代码。但是当我尝试使用这个 genmodel 生成代码时,它只会生成没有 OCL 表达式的代码。我还应该怎么做才能从一个单独的文件为所有 OCL 表达式生成代码?

这是我的模型文件:ecore file

这是我的 genmodel 文件:.genmodel file

OCL 文件的开始:

import 'CarRental.ecore#/'

package CarRental

context Person
inv Person3:
  age > 0 and age < 80

context Person::fullName : String
  derive: self.firstname.concat(' ').concat(self.lastname)
...
endpackage

OCLinEcore 中的模型文件:

package CarRental : CarRental = 'http:///CarRental.ecore'
{
    class Person
    {
        operation email() : String[*|1];
        operation updateAge(newAge : ecore::EInt[1]);
        attribute firstname : String[?];
        attribute lastname : String[?];
        attribute age : ecore::EInt[1];
        attribute isMarried : Boolean[1];
        attribute fullName : String[?] { derived };
    }
...
}

【问题讨论】:

    标签: ocl ecore


    【解决方案1】:

    应在 Eclipse OCL 新闻组上提出一个直接的 Eclipse 问题。

    https://www.eclipse.org/forums/index.php/f/26/

    您的 Ecore/GenModel 文件不是 Ecore/GenModel 文件;它们是顶级声明的快照。快照很少能很好地替代文件。

    您的 genmodel sn-p 看起来不错,但是如果没有项目的其余部分,很难评论您可能犯的许多错误。

    我的最佳猜测是,鉴于您发布的是示例 Ecore 模型编辑器快照而不是 OCLinEcore 编辑器快照,您未能合成注册 OCL 附加组件所需的所有 EAnnotation。 OCLinEcore 编辑器会自动完成这一切。

    我建议您将压缩项目发布到 Eclipse OCL 新闻组。

    【讨论】:

    • 好的,我没有合成 EAnnotations,因为在 OCLinEcore 中根本没有符号。我如何准确地自动或手动合成它们?
    • 如果您使用 OCLinEcore 编辑器编辑 Ecore 文件,它应该会发生。
    【解决方案2】:

    在 Eclipse OCL 论坛上提供了详细信息后,发现没有可用于生成代码的 OCLExpressions。零输入 => 零输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-14
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多