Find usages of lombok generated constructor in Intellij

醉酒当歌 提交于 2019-12-12 10:32:53

问题


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.



来源:https://stackoverflow.com/questions/38744874/find-usages-of-lombok-generated-constructor-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!