【问题标题】:Why does the error method return an error?为什么error方法会返回错误?
【发布时间】:2023-03-18 17:32:01
【问题描述】:

我要验证对应以下语法sn-p的输入:

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))
    }
  }

但是,当我使用 testCaseit 测试此验证时,会返回一条错误消息:

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 的问候

【问题讨论】:

    标签: xtext xtend


    【解决方案1】:

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

    【讨论】:

    • 应该在我的问题中提到你已经发现了......我的问题是关于异常的原因......还是谢谢你
    【解决方案2】:

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

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-10
      • 1970-01-01
      • 2016-01-08
      • 2016-08-30
      相关资源
      最近更新 更多