IDEA GDSL 如何向文件夹中的所有文件(类)添加方法定义?
在我的 Grails 应用程序中,有一个文件夹 grails-app/mongoDomain。在这个文件夹中,有几个类也位于不同的包中。
我想为文件夹 grails-app/mongoDomain 内的所有类添加“save()”方法的 GDSL 定义。
我成功地能够将此方法添加到单个类中,但是可以在 grails-app/mongoDomain 中的所有类中添加任何方法吗? .
.
我尝试这样做,但它不起作用..
def mongoDomainContext = context(pathRegexp: /.*grails-app\/mongoDomain.*/)
contributor(mongoDomainContext) {
method(name: 'save', type: 'void', params: [closure: { }])
}
但是上面的代码不起作用,正确的方法是什么?
.
.
问候 库沙尔
In my Grails Application, there a folder grails-app/mongoDomain. In this folder there are several classes that too in various packages.
I want to add a GDSL Defination for a method say "save()" to all classes inside the folder grails-app/mongoDomain.
I was successfully able to add this method to a single class, but any method to add in all classes in grails-app/mongoDomain??
.
.
I tried Doing this, but it did't worked..
def mongoDomainContext = context(pathRegexp: /.*grails-app\/mongoDomain.*/)
contributor(mongoDomainContext) {
method(name: 'save', type: 'void', params: [closure: { }])
}
But the above code did't worked, What is the right method for doing it??
.
.
Regards
Kushal
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,目前还没有这样的 GDSL 原语。在 Griffon 中,他们具有以下使用未记录功能的 GDSL 片段:
}
它们在类名及其路径上都匹配,您只需要贡献者调用内的第二部分。
Unfortunately, there's no such GDSL primitive yet. In Griffon, they have the following GDSL fragment using undocumented features:
}
They match on both class name and its path here, you need only the second part, inside the conributor call.
这是我的做法并且有效。非常感谢 Peter Gromov 提供提示。
它就像一个魅力。感谢大家。
Here's how I did it and it works. Great thanks to Peter Gromov for providing the hint.
It worked like a charm. Thanks to all.