2015-05-29 46 views
0

我想验证符合下列语法片断输入:为什么错误方法返回错误?

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 ([email protected] (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null 
ERROR ([email protected] (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null 

我只是无法弄清楚它有什么问题,所以我希望你们中的某个人可能有一个想法。

问候Krzmbrzl

回答

0

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

enter code [email protected] 
    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

1

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

+0

在我的问题,你发现了已经......我的问题是关于相当异常的原因应该提到它...谢谢你啦 – Raven

相关问题