2015-03-02 123 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与地图,这取决于上下文)。