使用LOMBOK时设定器的代码参考

发布于 2025-02-06 23:21:53 字数 231 浏览 2 评论 0原文

我想在我的项目中使用Lombok。

我正在使用Eclipse IDE进行开发。我可以在编译时间内为该项目设置Lombok。

但是有一个关于代码导航/参考的基本问题。

通常,我们可以通过在setter中或使用参数构造函数中查找引用来确定变量的设置。

由于Lombok具有自动生成这些样板。如何进行这些类型的代码导航,查找设置器/构造函数的引用?

最好的问候,

索拉夫

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天暗了我发光 2025-02-13 23:21:53

打开“轮廓”视图(如在实际视图中,而不是Quick-NAV弹出窗口)。

从菜单:窗口,显示视图,大纲。

开箱即用,Eclipse显示了代码右侧的此视图。您可能已经在屏幕上的某个地方拥有此视图;如果您没有该菜单选项,则该选项将启用它,或者如果您这样做,则将其显示/激活它:现在您知道了您要寻找的内容:)

在此大纲视图中,您会看到Lombok生成的方法,好像它们一样是正常写的。换句话说,如果lombok生成getName(),则getName在此列表中,与手动书面方法无法区分。双击它将导航您到导致Getter存在的注释(无论是@getter in Class还是在类上,或@data,或<代码> @value )。您还可以从此处激活“显示调用层次结构”选项:右键单击它并选择“显示调用层次结构”选项(开箱即用,它具有键盘快捷键。在Macs上,它是Ctrl+Alt+C;不知道它默认为Windows)。这向您显示所有呼叫者。

伦波克自己的注释也可以简单地被简单地使用,就好像它们是二传手一样 - 您可以直接从注释中调用“查找呼叫者”。但是,这并不总是合适的。例如,@data生成了一小部分方法,因此只能以这种方式对其中一个进行调查。当您在一个字段上(仅生成一个Getter)时,EG Stick @getter时,它的效果很好,但对于Eg @getter并不是特别有用。 @data在整个类型上。您必须为此使用大纲。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文