[英]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. 在项目中有很多类似的类,并且所有其他类都是在其他类的构造器/设置器中注入的EJB。
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. 在IntelliJ中,当我想导航到某个类时,我只能键入类名称,而IDE会找到所有类并返回选项列表。 You can imagine that this lists often consists of more than 15-20 different classes and navigating and finding the desired one is difficult. 您可以想象,该列表通常包含15-20多个不同的类,并且导航和查找所需的类很困难。
However, I would like to open a class, which has a name equal to ClassName
and is annotated with some annotation (like @SomeCountrySpecific
). 但是,我想打开一个类,该类的名称等于ClassName
并带有一些注释(例如@SomeCountrySpecific
)。
Is this possible in IntelliJ? 在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. 另一种方法是使用按类名导航(Ctrl + N)打开定义了注释的文件,然后对其名称运行“查找用法”(Alt + F7)。
Using this approach you will have autocompletion for annotation names which can be much longer that @SomeCountrySpecific
使用这种方法,您将可以自动完成注释名称的填充,而注释名称的填充时间可能比@SomeCountrySpecific
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.