Find usages of lombok generated constructor in Int

2019-06-16 10:28发布

问题:

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?

回答1:

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)


回答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.



回答3:

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.