Find usages of lombok generated constructor in Intellij
Asked Answered
M

3

21

I have a class with lombok annotation (either @Value or @Data) and I am looking for an easy way to find usages of the auto generated constructor.

What I can do now is to find a one use of the constructor, put the cursor there and run 'Find usages' command and I get the results I want.

However I would like to do this directly from the class declaration. Is there a way to do that?

Malan answered 3/8, 2016 at 13:21 Comment(0)
M
38

I have finally found an acceptable solution to this:

  1. Anywhere in the file invoke "File structure" action (Ctrl + F12 on linux)
  2. Select the desired element (constructor, but also works for Lombok generated builder() method when @Builder is present).
  3. Invoke "Find usages" action (Alt + F7 on linux)
Malan answered 22/2, 2017 at 14:53 Comment(2)
Cool, even the Call Hierarchy view works (to see who is calling)! Just press control+option+H (mac) while inside the File Structure popupMosesmosey
If anyone is wondering. This currently does not work in case the @Builder annotation is placed on the constructor method itself.Longspur
G
2

Not as easy as Find Usages, but you could use Structural Search for this. Use the button Copy existing template... and choose new expressions:

new $Constructor$($Argument$)

Edit variables to set the text/regexp of Constructor to your classname.

Gendarmerie answered 27/10, 2016 at 8:58 Comment(1)
Thank you for your answer. Unfortunately this is even more complicated than what I am doing now :-/Politico
N
1

You can search for usages of the type (the class declaration). IDEA will display the usages grouped by usage type. There you will find "new instance creation".

This works for me with IDEA Ultimate 2016.3 and lombok plugin.

Numismatology answered 26/1, 2017 at 13:23 Comment(1)
This is quite close to what I need, however expects me to group usages by type :-/Politico

© 2022 - 2024 — McMap. All rights reserved.