【问题标题】:OCL constraint using Ecore classifiers - Unknow type exception使用 Ecore 分类器的 OCL 约束 - 未知类型异常
【发布时间】:2012-06-07 09:12:01
【问题描述】:

我正在使用 OCLinEcore 编辑器开发一个在 OCL 中定义了一些不变量的 Ecore 模型。在我的模型中,一些元素引用了 EClassifier;在某些 OCL 约束中,我需要检查所引用的 EClassifier 是 EDataType 还是 EClass。在 OCLinEcore 中,这是一个类似于我的模型:

import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/';

package Foo : foo = 'some_namespace'
{
  class EndPoint
  {
    attribute name : String[1];
    property type : ecore::EClassifier[1];
  }

  class Coupling
  {
    invariant Compatibility:
      (destination.type.oclIsKindOf(ecore::EDataType) and source.type = destination.type) or
      let destinationClass : ecore::EClass = destination.type.oclAsType(ecore::EClass) in
      destinationClass.isSuperTypeOf(source.type.oclAsType(ecore::EClass));

    property source : EndPoint[1];
    property destination : EndPoint[1];
  }
}

但是,当我尝试验证模型的动态实例时,会出现异常并显示以下消息:

委托评估时发生异常 “耦合”上的“兼容性”约束:未知类型([ecore, EDataType])

当我在 OCL 交互式控制台中尝试表达式时,我得到了正确的结果。定义我的不变量时我做错了什么吗?如何编写使用 Ecore 类型的不变量?

【问题讨论】:

    标签: eclipse-emf eclipse-emf-ecore invariants ocl


    【解决方案1】:

    Edward Willink 在the OCL forum 上给了我一个解释和解决方法:

    裸 OCL 不支持将 ecore 绑定到有用的东西, 所以 oclAsType(ecore::EClass) 有一个未解析的引用,因为每个 ecxpression 是 ECore 文件中的一个独立的 sn-p。

    因此,Juno 版本添加了一个扩展,其中一个包 qualifier 可能是一个 URI,所以如果你看到上面的序列化它 可能 oclAsType(_'http://www.eclipse.org/emf/2002/Ecore'::ecore::EClass)。

    Juno 版本还增加了您是否使用新版本的灵活性 使用此扩展功能进行枢轴绑定。在里面 Window->Preferences->OCL page 确保选择的执行器 默认委托是 http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot.

    【讨论】:

      猜你喜欢
      • 2021-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多