Home > Blockchain >  Code references of setters when using Lombok
Code references of setters when using Lombok

Time:06-15

I want to use lombok in my project.

I am using Eclipse ide for development. I could setup lombok for the project in the compile time.

But have a basic question on code navigation/references.

Typically we could find out how the variable is set by finding the references in the setter or the with arguments constructor.

Since Lombok has auto generation of these boilerplate. How to do these type of code navigation, finding references of the setters/constructors ?

Best Regards,

Saurav

CodePudding user response:

Open the 'outline' view (as in, the actual view, not the quick-nav popup).

From the menu: Window, Show View, Outline.

Out of the box, eclipse shows this view already on the right side of your code. Likely you already have this view somewhere on your screen; that menu option will enable it if you don't have it, or show it/activate it if you do: Now you know what you're looking for :)

In this outline view, you see the methods that lombok generates as if they were written normally. In other words, if getName() is being generated by lombok, getName is in this list, indistinguishable from manually written methods. Double clicking it will navigate you to the annotation that caused the getter to exist (be it a @Getter on the field, or on the class, or @Data, or @Value). You can also activate the 'show call hierarchy' option from here: Right click it and pick the 'Show Call Hierarchy' option (out of the box, this has a keyboard shortcut. On macs, it's CTRL ALT C; no idea what it defaults to on windows). This shows you all callers.

Lombok's own annotations can also simply be used as if they were the setter - you can invoke the 'find callers' straight from the annotation. However, this isn't always suitable; for example, @Data generates a small army of methods, and therefore only one of those can be investigated in this fashion. It works great when you e.g. stick @Getter on a field (as that generates just the one getter), but isn't particularly useful for e.g. @Getter or @Data on an entire type. You'll have to use the outline for this.

  • Related