Typically in Spring Source Tool Suite IDE or Eclipse Maven project, if I want to see what a framework/library method is doing behind the scenes, I can ctrl + click on the method name and it will take me to the source code. I understand that a lot of Grails methods are added dynamically at runtime so its not always possible for the IDE to know how to get to them. Otherwise I can search for the class by package on Google, Github or the API documentation. What is the best way to do this with Grails core source to better understand the framework?
For instance I want to see what the respond method in a controller looks like and how its returning a parameter called "clubInstanceList" to my club/index gsp when the index method looks like:
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond clubService.list(params), model:[clubInstanceCount: clubService.count()]
}
ctrl + click doesn't work in the IDE since this method is added at runtime. I have searched through the Grails core source on github, but don't know the package structure for this respond method on a controller.
That's may be not a trivial search, because some code is generated during compilation time, or features can be added to your classes at runtime. This is the price that you pay when using dynamic languages.
Dynamic Runtime Methods
When I need to find some functionality that's not so obvious I start by trying to find the internal plugin that's responsible for that. In STS I do
ctrl
shift
T
and search for*GrailsPlugin*
. You can check for runtime changes in thedoWithDynamicMethods
closure of the plugin.For example, Grails have the
ControllersGrailsPlugin
class that add databinding features for your controller classes.Search For Methods
Since I didn't find anything related to the
respond
method in this plugin descriptor, this is probably made by compilation. You could usectrl
H
, and do a Java search, markingmethod
in the "search for" box. In thescope
markworkspace
and STS will look for Grails classes too.The Answer
So the answer your your question is the
ControllersRestApi
class, and I found it using the "search method" approach.