龙目岛如何在现有类上生成代码? [英] How Lombok generates code onto existing class?

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

问题描述

我可以使用注释处理器从头开始生成类,但是我不能像lombok那样修改类.我在android studio中搜索了由lombok生成的类,但是我什么也没找到.然后我通过他们的网站查看了龙目岛概述,并在论坛中进行了调查,但最终我没有任何帮助.我的问题其实很简单.例如,在我使用@Setter时,lombok如何与矿井统一生成的代码.我该如何开发诸如这样的处理器?

I can generate classes from scratch using annotationprocessor but I could not modify a class like lombok does. I've searched for the generated classes by lombok in android studio however I found nothing. then I checked the lombok overview via their website and also investigated it in forums but I've reached at end without anything. My question is so simple actually. How lombok unifies the generated code with mines while I use @Setter for instance. How can I develop a processor such as?

推荐答案

好像是的副本龙目岛工作吗?,我会标记为欺骗,以将其关闭,但您的赏金阻止了它.

Seems like a duplicate of How does lombok work?, and I would flag to close as dupe but your bounty's preventing it.

简而言之,Lombok实际上根本不会生成代码.相反,它使用未指定且未记录的内部编译器实现api调用来直接修改程序的抽象语法树,介于读取源代码和输出已编译字节码之间.可能会在没有警告或通知的情况下中断更新到新的编译器版本,但是目前没有其他方法.

In short, Lombok doesn't actually generate code at all. Instead, it uses unspecified and undocumented internal compiler implementation api calls to directly modify the program's abstract syntax tree between reading the source code and outputting compiled bytecode. It could break without warning or notice on updating to a new compiler version, but there's currently no other way.

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

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