How Lombok generates code onto existing class? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-06 18:16:41

问题


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?


回答1:


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

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.




回答2:


Lombok is generating code during the compilation phase. Here is a tutorial for that http://hannesdorfmann.com/annotation-processing/annotationprocessing101 .

If you are all new to declaring your own annotations i strongly recommend getting started with runtime annotations. They are easier to understand and debug and your code "acts" during the runtime phase you are already familiar with. A short tutorial for that: http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html



来源:https://stackoverflow.com/questions/40400648/how-lombok-generates-code-onto-existing-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!