首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么错误方法返回错误?

为什么错误方法返回错误?
EN

Stack Overflow用户
提问于 2015-05-29 14:25:47
回答 2查看 170关注 0票数 0

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

代码语言:javascript
运行
复制
Declaration:
    name = ID "=" brCon=BracketContent
;

    BracketContent:
        decCon=DecContent (comp+=COMPARATOR content+=DecContent)*
    ;

        DecContent:
            (neg=("!"|"not"))? singleContent=VarContent (op+=OPERATOR nextCon+=VarContent)*
        ;

我的验证如下:

代码语言:javascript
运行
复制
  @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测试此验证时,将返回一条错误消息:

代码语言:javascript
运行
复制
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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-31 15:44:47

结果发现这是一个内部错误.我仍然不确定到底出了什么问题,但是我已经重写了我的验证方法,现在它像预期的那样工作了。

现在,该方法如下所示:

代码语言:javascript
运行
复制
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

票数 0
EN

Stack Overflow用户

发布于 2015-05-29 14:50:01

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30532135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档