Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search for classes annotated with a given annotation in IntelliJ?

I have a project where many classes have one and the same simple name, but are decorated with different annotations.

For example:

package com.example.base;

@Default
public class ClassName { }

and

package com.example.country;

@SomeCountrySpecific
public class ClassName extends com.example.base.ClassName { }

There are many classes like these within the project and all are EJB injected within other classes' constructors/setters.

In IntelliJ, when I want to navigate to some class, I can type only the class name and the IDE finds all the classes and gives back a list of options. You can imagine that this lists often consists of more than 15-20 different classes and navigating and finding the desired one is difficult.

However, I would like to open a class, which has a name equal to ClassName and is annotated with some annotation (like @SomeCountrySpecific).

Is this possible in IntelliJ?

Please note that renaming the sub-classes is not an option.

like image 359
Konstantin Yovkov Avatar asked Oct 19 '25 07:10

Konstantin Yovkov


1 Answers

It's not very elegant or all that convenient, but this might get you what you're looking for (?). You can use the file mask and "Text to find" to search for annotations in files named by some pattern.

enter image description here

like image 174
MadConan Avatar answered Oct 20 '25 20:10

MadConan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!