Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find usages of lombok generated constructor in Intellij

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?

like image 962
František Hartman Avatar asked Aug 03 '16 13:08

František Hartman


People also ask

How do I see the usage of a method in IntelliJ?

In the editor, select a symbol for which you want to see the usages. From the main menu, select Edit | Find Usages | Show Usages In Code Ctrl+Alt+F7 . The usages window shows the current scope and total count of usages. If you want to quickly switch to the default scope, press Ctrl+Alt+F7 .

How do I check my Lombok generated class?

Find generated class in folder target/././classname. class and open it in IntelliJ IDEA.

Where is usage method in IntelliJ Mac?

Press ⌥F7 (macOS), or Alt+F7 (Windows/Linux), to bring up the Find Usages tool window. You can search a single file, your whole project, or customise the scope. You can also configure the color of the usages highlighting or disable the automatic highlighting of usages.


2 Answers

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)
like image 119
František Hartman Avatar answered Sep 21 '22 10:09

František Hartman


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.

like image 43
Bas Leijdekkers Avatar answered Sep 18 '22 10:09

Bas Leijdekkers