Scope "Module" difference between Find in Files (Strg Shift F) vs Usage Search (Strg Alt F7)

Answered

Hello

I am wondering about IDEA behaviour in terms of Find in Files vs Usage Search when it comes to selecting Scope “Module”.

Say I have a Java EE webproject with src/main/java, src/main/resources, and src/main/webapp (for faces stuff, xhtml etc.).

Now within a .java file when doing “Find in Files (Strg Shift F)"  I can select scope ”Module" and e.g. myproject.main. This will give me results from within the src/main/java files but also from within src/main/webapp.

When doing a usage search with Strg Alt F7 on a field that is referenced within xhtml files via EL-expression (e.g.: #{myBean.someProperty}) selecting Module ‘myproject.main’ will only yield usages within .java files; but NOT the usages within src/main/webapp xhtml files. (in the end this is main Module as well, isn't it?)

However at the bottom of the Usage Search window there is a hint "…<# usages are out of scope 'Module myproject.main>… Why this?

When I click on this hint the Module selector above will switch to “Project Files” and the *.xhtml files from src/main/webapp are shown.

I dont't get this difference. Why does usage search on Module not cover src/main/webapp while Find in Files does?

0
2 comments

Hi Rob,

Thanks for the detailed explanation and examples.

Short answer: this difference is expected at the moment and comes from how Find in Files and Find Usages define and apply their scopes.

Why the results differ:

  1. Find in Files (Ctrl+Shift+F)
    • This is a text-based search
    • When you select Scope: Module <myproject.main>, IDEA looks at the module’s content roots and searches all files under them, including src/main/java, src/main/resources, and src/main/webapp
    • That’s why you see matches both in Java and in your *.xhtml files.
  2. Find Usages (Alt+F7)
    • This is a code-aware search: it works on symbols (fields, methods, etc.), not just text
    • Internally, IDEA first calculates the element’s use scope (where this symbol can reasonably be referenced) and then intersects that with the scope you choose in the UI (in your case, Module <myproject.main>)
    • For Java fields, that use scope is generally narrower and, in your setup, it currently does not include the web resource root where the *.xhtml files live, even though those files belong to the same module from the project-structure point of view
    • As a result, usages in src/main/webapp are found by the code that understands EL, but they are considered outside the active scope. That’s why you see the hint at the bottom, N usages are out of scope 'Module myproject.main', and why switching the scope to Project Files immediately reveals those usages.

So in practice, “Module” in Find in Files = whole module content roots, while “Module” in Find Usages = element’s code use-scope in the selected module, which currently treats the web root differently.

 

What you can do now:

  • When you need a complete picture of usages including EL in *.xhtml, run Find Usages and:
    1. Either click the hint at the bottom and switch the scope to Project Files
    2. Or open the Find Usages dialog (Ctrl+Alt+Shift+F7) and explicitly choose Project Files (or Project and Libraries) in the Scope field.
  • If you only need text occurrences and don’t care whether they’re semantic usages, keep using Find in Files with Scope: Module <myproject.main>
0

Ok @... . Thx for the thorough explanation!

0

Please sign in to leave a comment.