简体   繁体   English

如何找到所有具有实现intelliJ中指定接口的类的字段?

[英]How to find all fields having classes that implement specified interface in intelliJ?

I'm trying to find all fields with the Disposable interface, so I can know if whether I forgot to call the dispose() method on any of them in the cleanup phase. 我正在尝试使用Disposable接口查找所有字段,因此我可以知道是否在清理阶段是否忘记对它们中的任何一个调用dispose()方法。

Is there a way to do that in intelliJ? 有没有办法在intelliJ中做到这一点?

I've only managed to find those, whose dispose() methods I've already remembered to call. 我只是设法找到那些我已经记得要调用的dispose()方法。 I've done that by ticking the "Usages of methods" checkbox in the find usages options dialog (when doing a search on the Disposable interface)... but this wasn't what I need. 我已经通过在“查找用法”选项对话框中选中“方法的用法”复选框(在Disposable界面上进行搜索时)来完成此操作……但这不是我所需要的。

You can try Edit | 您可以尝试编辑| Find | 找到| Search Structurally. 在结构上搜索。 You can copy a predefined template named "fields of class" that can be modified to your needs by removing Init part and specifying a hierarchy constraint for $FieldType$ variable. 您可以复制一个名为“类的字段”的预定义模板,可以通过删除Init部件并为$ FieldType $变量指定层次结构约束来修改此模板。

You can read more about that functionality at https://www.jetbrains.com/idea/help/structural-search-and-replace.html 您可以在https://www.jetbrains.com/idea/help/structural-search-and-replace.html上了解有关该功能的更多信息。

**Alt+F7**

Instead of the dispose method, find usages of the interface 而不是dispose方法,找到接口的用法

Usages - if this check box is selected, the search is performed for all references of the class by its name. Usages - 如果选中此复选框, Usages名称对该类的所有引用执行搜索。

This way you will get all the places where Disposable interface is being referenced in your workspace 这样,您将获得工作区中引用Disposable接口的所有位置

You can find usage of the your interface. 您可以找到您的界面的用法。 The keycode for that in my system is alt+f7, but it can be different on your system. 我系统中的密钥代码是alt + f7,但它可能与您的系统不同。 So you can right click and find usage of your interface. 因此,您可以右键单击并find usage界面的find usage and then filter it down to Usage in extends/implements clause 然后将其过滤到Usage in extends/implements clause

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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