Find usages of primary constructor of a Kotlin class
You should put the caret next to the opening parenthesis of the primary constructor but not right before the first parameter. Possibly add a space or line break:
class MyAwesomeManager<caret>(argOne: String, argTwo: String)
//also works
class MyAwesomeManager(<caret> argOne: String, argTwo: String)
then invoke Find Usages. This should give you only the usages of the constructor invocation.
If there are no parentheses because the class has a default zero-argument constructor, you can temporarily add ()
after the class name, then proceed as above.
Since your "Find Usages" call (Alt+F7
on OSX) is from the Kotlin class name (which is also the constructor definition), you'll get more results than you would have if you'd done the same on a Java constructor - as you saw. If Find Usages didn't show usages of the class from this point, how else would you know where the class is used?
Doing this on one of my own Kotlin classes, I got the following:
Expanding "New instance creation" shows me constructor usage.
I'm sorry for so quickly answering my own question, but I guess I've found a solution. In two simple step:
- Double-click the name of a class to select it
- 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.