Finding Groovy Method Usages in GSP Code

Hi,

I just broke my Grails application (in a very minor way) 'cause I missed a usage of a renamed Groovy method that was called from GSP.

Could JetGroovy make Find Usages extend its scope of analysis to GSP code?


Thanks.


Randall Schulz

0

Randall,
Could you attach some sources to reproduce this omission. If I undersood right, you tried to call some Groovy method from Groovy injection in GSP.
Are you sure, that this method referenced correctly to its definition?

0

Yes, I had a call to a Groovy method from an attribute value in a GSP tag:

]]>

Everything was working before I renamed the method groupNames() to be groupPrefixes(). I did a Find Usages before renaming it, and it found the usages in other Groovy source files, but not the ones in the GSP files.

Perhaps the problem lies in the fact that while the GSP page variable (if that's the proper term) "settings" is definitely an instance of the Grails domain class "Settings", the methods in question (groupNames() before the renaming, groupPrefix() after) are a static methods.


Randall Schulz

0

It seems to me that you try to invoke method 'Settings' class as though as in GSP views related to appropriate domain class.
That's true, there respective domain class instance can be referred by low-case-letter name. But at given moment such references are not supported by JetGroovy plugin. BTW, if you refer to class (not to it's instance), you could invoke static method, and this fact will be observed by IDEA:

<g:each in="${Settings.groupPrefixes()}" var='groupPrefix'>

0
Avatar
Permanently deleted user

Hm, it works with no problem here. "Dynamically typed" usages are found and renamed...
Any additional information please?

Eugene.

0

Sorry, but in your case find usages command works correctly as well (GSP occurrences pass as "unclassified usages", that should be renamed).
Thus, I cannot reproduce this bug.

0

Changing it to invoke the static method via the class name instead of the instance still does not work.

But I kept poking around with it and discovered this:

If I change the search scope from the current module ("Module 'tau'") to "Project Files" then it works. (The GSP and the Grails domain class are in the same module, of course.)

Also, I'd changed one of three GSP uses from invoking the static method via an instance to invoking it via the class name. The two unchanged (dynamic) uses were categorized "Dynamically typed uses" and the one I'd changed to static was under "Found uses". I believe that's how you intend it to work.


So it seems the only problem is that when using the module scope in the "Find Usages" dialog, the GSP references (whether dynamic or static) are not found.


Randall Schulz

0
Avatar
Permanently deleted user

Hello Randall,
it turned out that 'views' directory is not included as a source root for your grails module.
Adding it fixes the problem. I've modified the logic for creating grails module to include 'views' as a source root by default, but for existing projects you would need to add those source roots manually:(

Eugene.

0

OK. Thanks.

I just looked at my project outline. The "views" directory is shown with a yellow folder icon.

A "source root" (also known as a "Content Root" in the Project Settings dialog?) is shown in blue, correct?

So when I add (yet) another root for "views" directoyr, the icon should change to blue and a module-scoped search will include source files therein, including GSPs?


Actually, this entire Grails app was integrated into my IDEA project manually. As part of that, I added Content Roots to the module for each of the relevant Grails sub-directories, but I see now that even though I added a Content Root for the "views" directory, I neglected to add a source directory to that Content Root.

So I guess this was cockpit error all along.


OK. I added a Source Folder to the Content Root I'd added earlier for the "views" directory and as I expected, the icon for tha folder turned blue and the folders nested beneath it are yellow with a blue dot. Futhermore, module-scoped searches now find usages in the GSP files under "views."


Thanks!


Randall Schulz

0
Avatar
Permanently deleted user

Content directories are not the same as source ones, but any source directory is placed somewhere inside content directory subtree. First you add content root, and then you mark something inside it as source or testsource.
And yes, source roots are marked in blue.

0

请先登录再写评论。