You know how you can go to the edit menu in IntelliJ, pick “Find”, and then pick “Find in Files”? That opens a dialog box. And in the upper right, you can pick a File Mask.

Where the File Mask is located
File Mask location

Hopefully you’ve tried that out! And hopefully you’ve realized it can take wildcards as well, so:

pom.xml to search only Maven poms
*.java to search all java files

But what if you want to search your code for something but don’t care about the unit test and integration test classes? Tough! You get hits from everything, and you’ll just have to visually search through it all. So that made me dig some more trying to see what else I could do. And it turns out that the File Mask supports a “not” operator!

!*Test.java will search everything but files that end in Test.java – so everything but unit tests.

AND you can combine terms with commas! And that gives us enough pieces to make searching across files much more useful.

To complete the example above, this will search just java code files while excluding all unit and integration test files:
.java,!Test.java,!*IT.java

This made my day, because I am a huge nerd and love finding out stuff like this.

Categorized in:

Tagged in: