龙目岛如何运作? [英] How does lombok work?

查看:25
本文介绍了龙目岛如何运作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天遇到了 lombok.
我很想知道它是如何工作的.
一篇 Java Geek 文章 提供了一些线索,但我不太清楚:

I met lombok today.
I'm very anxious to know how it works.
A Java Geek Article gives some clues but it's not perfectly clear to me:

Java 6 移除 apt 并使 javac 可用管理注释,简化获得更简单的过程单步计算.这是龙目岛走过的路.

Java 6 removes apt and make javac able to manage annotations, streamlining the process to obtain a simpler single step computing. This is the path taken by Lombok.

也许对于 Java 6,编译过程将是:javac -> apt -> lombok apt 进程 -> 使用 ASM?

Maybe with Java 6 the compile process will be: javac -> apt -> lombok apt process -> read class files and add set/get methods using ASM?

你能告诉我更多关于这个机制的细节吗?

Could you show me more details about the mechanism?

推荐答案

Lombok 确实针对内部 API 进行编码,正如 Sean Patrick Floyd 所说.但是,由于 lombok ONLY 参与编译阶段,因此声称 Lombok 只能在 sun VM 上运行是误导性的.它只会在 ecj 或 sun 的 javac 上编译.然而,绝大多数的虚拟机,如果它们有编译器的话,都是这两者之一.例如,Apple VM 附带股票 sun javac,因此 lombok 在 mac 上运行得很好.例如,soylatte VM 也是如此.

Lombok does indeed code against internal API, as Sean Patrick Floyd said. However, as lombok is ONLY involved in the compilation phase, its misleading to claim Lombok will only run on a sun VM. It'll only compile on ecj or sun's javac. However, the vast majority of VMs out there, if they ship a compiler at all, are one of those two. For example, the Apple VM ships with stock sun javac, and as such lombok works just fine on macs. Same goes for the soylatte VM, for example.

虽然对于 javac,我们确实必须坚持他们的更新,部分原因是他们的编译器目前正在进行大量工作,我们只需要对许多 eclipse 版本的 eclipse 支持进行 1 次小调整.因此,当我们针对内部 API 编写代码时,它们是相对稳定的位.

While for javac we really do have to stick with their updates, partly because of a lot of ongoing work on their compiler right now, we've had to make just 1 minor adjustment to our eclipse support over many many versions of eclipse. So, while we do code against internal API, they are relatively stable bits.

如果 lombok 所做的事情可以不借助内部 API 来完成,我们会做其他事情,但它无法完成,所以我们求助于内部 API 使用.

If what lombok does could be done without resorting to internal API, we'd have done something else, but it can't be done, so we resort to internal API usage.

注意:我是 lombok 的主要开发者之一,所以,我可能有点偏见:P

NB: I'm one of the lead developers of lombok, so, I'm probably a little biased :P

这篇关于龙目岛如何运作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆