为什么IntelliJ需要Lombok插件? [英] Why IntelliJ needs Lombok plugin?

查看:378
本文介绍了为什么IntelliJ需要Lombok插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,Lombok使用Java的注释处理器来生成其他方法.

As far as I understand, Lombok uses Java's Annotation Processors to generate additional methods.

使用Maven 3.5,它可以完美地工作,而无需添加任何其他配置,只需向Lombok添加Dependecy并添加一些注释,例如@Getter@Setter.

With Maven 3.5 it works perfectly without adding any additional configuration, just add dependecy to Lombok and put some annotations like @Getter, @Setter.

但是,如果我在IntelliJ IDEA 2018.2中打开此项目,则生成的getter/setter的所有用法都会突出显示为错误.我打开了注释处理功能,我试图在IntelliJ中构建项目或在Maven中构建,然后在IntelliJ中使用,但是它仍然需要Lombok插件来避免错误.

However, if I open this project in IntelliJ IDEA 2018.2, all usages of generated getters/setters are highlighted as errors. I have Annotation Processing turned on, I tried to built project in IntelliJ or build in Maven and then use in IntelliJ, but it still requires Lombok Plugin to avoid false errors.

是某种错误吗?工作流程错误?也许Lombok不仅在使用注释处理器,而且在使用其他我不知道的东西,这就是为什么IntelliJ + javac无法弄清楚如何处理它的原因?当javac本身编译这些文件而没有错误时,这会很奇怪

Is it some kind of bug? Error in workflow? Or maybe Lombok is using not only Annotation Processors, but some other stuff I didn't know and that's why IntelliJ + javac cannot figure out how to deal with it? It would be strange as javac itself compiles those files without errors

我知道我在使用Lombok时遇到错误"和使用插件"之类的问题有很多.我不是问我是否应该使用插件,而是为什么我应该使用它,为什么IntelliJ不能在Javac没有插件的情况下处理它

推荐答案

IntelliJ的代码分析引擎不使用javac或运行注释处理器.相反,IntelliJ使用自己的Java解析器和参考解析逻辑,并构建自己的代码模型. Lombok插件扩展了代码模型,以提供有关Lombok批注处理器生成的声明的信息.

IntelliJ's code analysis engine does not use javac or run annotation processors. Instead, IntelliJ uses its own Java parser and reference resolution logic, and builds its own code model. The Lombok plugin extends the code model to provide information about declarations generated by the Lombok annotation processor.

这篇关于为什么IntelliJ需要Lombok插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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