简体   繁体   中英

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.

Is there a way to do that in intelliJ?

I've only managed to find those, whose dispose() methods I've already remembered to call. 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.

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.

You can read more about that functionality at https://www.jetbrains.com/idea/help/structural-search-and-replace.html

**Alt+F7**

Instead of the dispose method, find usages of the interface

Usages - if this check box is selected, the search is performed for all references of the class by its name.

This way you will get all the places where Disposable interface is being referenced in your workspace

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. So you can right click and find usage of your interface. and then filter it down to Usage in extends/implements clause

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