Drill Deeper into Jarrrrrs

Finding occurrences of a string or usages of a symbol across a project is a rather common task. However, it becomes less evident, if the goal of your search is hidden inside an archive. IntelliJ IDEA helps you easily drill into directories, libraries, zip or jar files.

Let’s consider two cases of search in archives:

  • Finding a text string
  • Finding usages of a symbol
If you want to locate a text string in an archive, you don’t even need to construct a scope. It is enough to select such zip or jar file, or one of the nested directories within it, in the Project view, click Ctrl+Shift+F to open the Find in Path dialog, and in the Scope section click the Directory radio-button. If you want to drill into the archive and its directories, select the Recursively check box. As you see, the suggested path includes nested directories in the selected jar file.

 

 

 

 

 

 

 

 

 

 

 

 

 

After clicking the Find button, the detected occurrences are displayed in the Find tool window.

As for finding usages of a symbol inside library sources, you have to define a dedicated scope. For this purpose, IntelliJ IDEA suggests the Scopes dialog. You can construct scopes in advance (Ctrl+Alt+S ->Scopes), or do it immediately in the Find Usages dialog (Alt+F7). This is how it's done:

Having invoked the search for usages of a selected symbol, click the ellipsis button next to the Scope field:












 

 


In the Scopes dialog, create a new scope (for example, LibraryScope) and populate it with module directories and library archives. Note that library classes and sources should be already defined and attached in the project settings. Though you can type the scope pattern manually, it is much easier to select the desired entries from the list. For your convenience, you can group entries by modules, or by scope types:

 

 

 

 

 

 

 

 

 

 

 

As you include or exclude the desired archives and packages, IntelliJ IDEA constructs the corresponding scope pattern:

 

 

 

 

 

 

 

 

 

 

 

 

 


After applying changes and closing the Scopes dialog box, click the Find button, and view results in the Find tool window.

Enjoy!

 

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)