1

我想知道是否可以禁用对元模型中指定的模型元素子集的验证。

问题是我在编写 dsl 文件时从 Xtexteditor 收到了一些验证错误。所以我的想法是禁用对这个模型元素的验证。我尝试构建一个真正简单的文本符号,并希望在保存文件时序列化(有效)模型。保存的模型在保存过程中被修改,所以最后才有效。

问候,亚历克斯

让我们从语法开始:我正在研究一个导入的元模型(UML2):

import "http://www.eclipse.org/uml2/4.0.0/UML"

然后我创建所有必要的解析规则来定义一个类图。就我而言,问题出现在类之间关联的解析规则中:

AssociationClass_Impl returns AssociationClass:
{AssociationClass} 'assoc' name=ID'{'
(ownedAttribute+=Property_Impl)*
'}';

当然还有属性的解析规则:

Property_Impl returns Property:
     name=ID ':' type=[Type|QualifiedName]
     (association=[AssociationClass|QualifiedName])?
     ;

现在对问题本身说几句。在运行时 eclipse 的 xtexteditor 中编辑 xtext 文件时,会验证构建模型。问题出在元模型本身对 AssociationClass 有几个约束(截图还不可能):

Multiple markers at this line
- The feature 'memberEnd' of 'org.eclipse.uml2.uml.internal.impl.AssociationClassImpl@142edebe{platform:/resource/aaa/test.mydsl#//Has}'   
  with 0 values must have at least 2 values
- The feature 'relatedElement' of 'org.eclipse.uml2.uml.internal.impl.AssociationClassImpl@142edebe{platform:/resource/aaa/test.mydsl#//Has}'  
with 0 values must have at least 1 values
- The feature 'endType' of 'org.eclipse.uml2.uml.internal.impl.AssociationClassImpl@142edebe{platform:/resource/aaa/test.mydsl#//Has}'
with 0 values must have at least 1 values
- An association has to have min. two ownedends.

现在我想知道是否可以禁用对这个模型元素的验证。所以我可以向用户隐藏错误信息。因为我想在下一步序列化创建的 xtextmodel 并且会做一些模型转换。

4

1 回答 1

1

似乎 UML 在全局单例注册表中注册了这个验证器。所以你基本上需要避免使用注册表。您可以通过在运行时模块中绑定不同的元素来做到这一点:

public EValidator.Registry bindEValidatorRegistry() {
    // return an empty one as opposed to EValidator.Registry.INSTANCE
    return new org.eclipse.emf.ecore.impl.ValidationDelegateRegistryImpl();
}
于 2013-11-29T07:45:20.923 回答