48

I'm using Eclipse with Lombok. The getters and setters are generated properly but they are not visible in class body (that's the whole point, I know). However, because of that, I am unable to execute a search for usages of a getter or a setter from inside the class. So if I want to check what and where actually sets a particular value of a field, I have to execute a String search for the getter name, which is slow and may give bad results (for a field of the same name in another class, for example).

Is there a way in Eclipse to look for a getter/setter usage for a field for lombok-generated methods?

Dariusz
  • 21,561
  • 9
  • 74
  • 114

3 Answers3

71

You can use the Outline view: outline view showing getter/setter

Right-click on the method in the Outline view, and use "Open Call Hierarchy".

An other way to do it is to right-click on the annotation (@Setter for instance), and use "Open Call Hierarchy" on it, but it may not work with some annotations (like @Data).

Florent Bayle
  • 11,520
  • 4
  • 34
  • 47
  • 10
    It does work for the outline, thanks for the answer. It is nice, but not very convenient. It doesn't work for the ctrl-o quick outline, which would've been nicer. – Dariusz Mar 07 '17 at 10:13
  • Keyboard shortcut Ctrl + Shift + G works in Outline too, after you select one of the method. – blackr1234 Mar 03 '20 at 20:51
  • It just work if the `@Getter` and `@Setter` is annotated on the the field. If the annotation is on the class (to create getter and setter to all fields) the "Open Call Hierarchy" doesn't work. Migrating from IntelliJ to Eclipse and I'm missing this :/ Is there any other way? – Renan Ceratto Nov 01 '21 at 18:12
  • @RenanCeratto, which version of Eclipse do you use? I need to do the trick in both 2020-12 and 2023-06. Regarding IntelliJ IDEA, AFAIK, it has got the same limitation - see https://stackoverflow.com/questions/45048246/how-to-build-call-hierarchy-for-lombok-generated-method-in-intellij-idea. – Petr Bodnár Jun 27 '23 at 17:35
  • @PetrBodnár Sorry, but I dont remember the Eclipse version and I'm back to IntelliJ IDEA 2023.1.3 (Ultimate Edition). Using intellij, it is possible to achieve this just by Ctrl+Click the field, using the Find Tool – Renan Ceratto Jul 05 '23 at 03:31
  • @RenanCeratto, unlike Ctrl+Shift+G in Eclipse, Ctrl+Click in IDEA indeed finds usages of the field AND its accessor methods. So what a pity IDEA doesn't support this in the Call Hierarchy view as well. – Petr Bodnár Jul 05 '23 at 08:50
0

Apart from finding the method in outline and then right click and find references, there is no other option as of now. Same holds good for constructors provided by lombok.

Kiran
  • 1
  • 1
-4

if you cant see getter and setters in outline tab.just restart the IDE.And also before importing the jar to IDE,Run the jar file and specify the IDE.exe file to it.

hero
  • 1
  • You're referring to the lombok jar which you can download from https://projectlombok.org/download. See https://projectlombok.org/setup/eclipse for clearer installation details. – mekazu Feb 26 '20 at 02:03