Search code examples
android-studiointellij-ideakotlinhotkeys

Find usages of primary constructor of a Kotlin class


Imagine you have a super important and widely-used class in your Kotlin-based project. It has the only constructor which is defined like that:

class MyAwesomeManager(argOne: String, argTwo: String)

For some reason, you need to quickly find all uses of its constructor. You're using Android Studio (or Intellj IDEA).

But... pressing Ctrl + LMB on its name gives a ton of rubbish results - uses in imports, companion object's fields calls etc. All the uses of a class, but not the constructor. The same for putting a cursor on its name and hitting Alt + F7.

So, how do I find all and only the usages of this primary constructor?


Solution

  • I'm sorry for so quickly answering my own question, but I guess I've found a solution. In two simple step:

    1. Double-click the name of a class to select it
    2. Ctrl+B to find usages (edit: Alt+f7 would also work)

    I'm not sure it works in all cases, but it worked for me.