为什么error方法返回一个错误



我想验证与以下语法片段相对应的输入:

Declaration:
    name = ID "=" brCon=BracketContent
;
    BracketContent:
        decCon=DecContent (comp+=COMPARATOR content+=DecContent)*
    ;
        DecContent:
            (neg=("!"|"not"))? singleContent=VarContent (op+=OPERATOR nextCon+=VarContent)*
        ;

我的验证看起来像这样:

  @Check
  def checkNoCycleInHierarchy(Declaration dec) {
    if(dec.decCon.singleContent.reference == null) {
        return
    }
    var names = newArrayList
    var con = dec.decCon.singleContent
    while(con.reference != null) {
        con = getThatReference(con).singleContent
        if(names.contains(getParentName(con))) {
            val errorMsg = "Cycle in hierarchy!"
            error(errorMsg, 
                SQFPackage.eINSTANCE.bracketContent_DecCon,
                CYCLE_IN_HIERARCHY)
            return
        }
        names.add(getParentName(con))
    }
  }

但是当我用testcase测试这个验证时,它返回了一个错误消息:

Expected ERROR 'raven.sqf.CycleInHierarchy' on Declaration at [-1:-1] but got
ERROR (org.eclipse.emf.ecore.impl.EClassImpl@5a7fe64f (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null
ERROR (org.eclipse.emf.ecore.impl.EClassImpl@5a7fe64f (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null

我只是不知道它有什么问题,所以我希望你们中有人可能有一个想法。

问候Krzmbrzl

您的测试实用程序告诉您验证器没有产生预期的验证错误("CycleInHierarchy")。相反,验证器产生了错误"执行EValidator时出错"。这意味着在执行验证器时抛出了异常。

原来是内部错误…我仍然不确定哪里出了问题,但我已经重写了我的验证方法,现在它按预期工作。
现在这个方法看起来像这样:

enter code here@Check
  def checkNoCycleInHierarchy(Declaration dec) {
    if(dec.varContent.reference == null) {
        //proceed only if there is a reference
        return
    }
    var content = dec.varContent
    var names = newArrayList
    while(content.reference != null && !names.contains(getParentName(content))) {
        names.add(getParentName(content))
        content = content.reference.varContent
        if(names.contains(getParentName(content))) {
            val errorMsg = "Cycle in hierarchy!"
            error(errorMsg,
                SQFPackage.eINSTANCE.declaration_BrCon,
                CYCLE_IN_HIERARCHY)
                return
        }
    }
  }

我怀疑在这种情况下我的"getThatReference"的使用有问题。

问候Krzmbrzl

相关内容

最新更新