追踪 Groovy 方法定义?

Tracking down a Groovy method definition?

Ruby 使您能够在运行时跟踪定义方法的文件和行。因此,例如,如果您有一个名为 "obj" 的对象,它能够调用方法 "do_something",您可以跟踪其定义(在 ruby 1.9 及更高版本中):

obj.method(:do_something).source_location

groovy是否有任何等效的能力?我试图追踪定义方法的位置,但事实证明这非常困难。

感谢您的帮助。

Does groovy have any equivalent capability?

没有。你不能审问一个对象并问它 "If I invoke the save method and pass no arguments, what file contains the definition for the save method that will actually be invoked and at what line number is that definition." 这样的问题。语言和运行时都没有专门为此提供便利。您可以做一些事情,例如询问堆栈以找出调用的来源,但这不是这里要问的。我想你的问题的答案是 "no".