18

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?

František Hartman
  • 14,436
  • 2
  • 40
  • 60

3 Answers3

32

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)
František Hartman
  • 14,436
  • 2
  • 40
  • 60
  • 1
    Cool, even the `Call Hierarchy` view works (to see who is calling)! Just press `control+option+H` (mac) while inside the File Structure popup – Johnny Willer Aug 19 '20 at 08:41
  • If anyone is wondering. This currently does not work in case the `@Builder` annotation is placed on the constructor method itself. – jimonthebarn Nov 23 '20 at 13:31
1

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.

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
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.

haja
  • 302
  • 2
  • 8