简体   繁体   English

如何在IntelliJ中搜索以给定注释注释的类?

[英]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.

相关问题 如何模拟使用@ConstructorBinding 注释的类 - How to mock classes annotated with @ConstructorBinding annotation 过滤带有特定注释的类 - Filter classes that are annotated with a specifi annotation 如何构建用我的自定义注释注释的类列表? - How to build a list of classes annotated with my custom annotation? 如何只允许在 Java 中的方法参数中使用某些注释进行注释的类? - How to allow only classes annotated with some annotation in method parameters in Java? 如何在springboot/java应用程序中使用给定的注释获取方法注释 - How to get Method annotated with given annotation in springboot / java app 如何在 IntelliJ IDEA 中找到顶级未注释的类 - How to find top level not annotated classes in IntelliJ IDEA IntelliJ 结构搜索以查找所有没有给定声明的类 - IntelliJ Structural Search to find all classes without given declarations 选择具有给定注释的类 - Select classes with given annotation 如何排除对使用特定注释注释但未使用其他注释注释的bean的扫描? - How to exclude scanning of beans that annotated with specific annotation and not annotated with another annotation? 如何创建仅包含用自定义注释注释的类/方法的JavaDoc? - How to create JavaDoc which contains only classes/method annotated with custom Annotation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM