2015-03-02 114 views
2

我有這個自動生成的代碼行:Groovy的:意外令牌「:」

EPRole validator: { EPRole r, EPUserEPRole ur -> 
      if (ur.EPUser == null) return 
      boolean existing = false 
      EPUserEPRole.withNewSession { 
       existing = EPUserEPRole.exists(ur.EPUser.id, r.id) 
      } 
      if (existing) { 
       return 'userRole.exists' 
      } 
     } 

當我嘗試編譯代碼我得到82: unexpected token: validator @ line 82, column 10.

我在常規新,所以任何幫助表示讚賞。

+2

應該是epRole? EPRole將是類 – cfrick 2015-03-02 22:11:31

+0

啊,現在我明白了。整個班級都是自動生成的,你說的錯誤取決於資本和小案例。我如何接受你的答案是正確的? – bel 2015-03-02 22:19:43

回答

2

你應該添加你的屬性與正確的類型和名稱的類。第一個字母大寫用於類(或通常的類型)。所以,應該有你的EPUserEPRole屬性是這樣的:

EPRole epRole 

然後添加驗證器epRole。請注意情況。

以上代碼會混淆的常規解析器成限定EPRole型後面是:的屬性validator,因此誤差(否則它會嘗試調用方法EPRole與地圖,這取決於上下文)。