简体   繁体   中英

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.

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.

在此处输入图片说明

尝试进行“结构化查找/搜索”。

Another way is to use navigation by class name (Ctrl+N) to open the file where the annotation is defined and then run "Find Usages" (Alt+F7) on its name.

Using this approach you will have autocompletion for annotation names which can be much longer that @SomeCountrySpecific

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM