2015-05-29 102 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