javakotlinintellij-ideaide

How to find all places where a class is used in a field definition in intellij?


Given a class definition, I can easily find all places where it is used in several ways, in a long list with some filtering options.

But what I want is to find fields of the type I am interested in, that is, I want look at a class definition and answer the question "Which classes have a field of this type?"

I am using Intellij IDEA 2023.2.5 with Java17, but I would appreciate answers even if they use different tools or work in different languages. A perfect answer would also find fields of a supertype of the class I am looking for but the simple answer of finding fields of the exact type is good enough.


Solution

  • "Find Usages" solves the problem. Activate with Alt+F7 (Windows) or Alt+Shift+F7 (Gnome) or ⌥Opt+F7 (Mac) or through the right-click-context-menu to find usages of the class under the cursor. The usages will be grouped, and one of those groups is "Field declaration".

    More info: https://www.jetbrains.com/help/idea/find-highlight-usages.html