使用用户定义的注释生成编译器警告
是否可以让编译器在遇到用户定义的注释时生成警告?类似于 @Deprecated 注释吗?
Is it possible for make the compiler generate a warning when it encounters a user defined annotaion? Something similar to the @Deprecated
annotation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据您最初的问题和评论,我假设您正在尝试执行以下操作:
我不相信你可以用编译器警告标记代码。
@Deprecated
标签已融入编译器中。指示方法不完整的更常见方法是抛出异常:throw new UnsupportedOperationException("Not Implemented Yet");
直到运行时才实现效果,但其他开发人员应该对他们的代码进行单元测试。
至于识别不完整的代码,我仍然会参考我原来的评论。使用
TODO
注释标签,Eclipse 将为您构建一个任务列表。如果您的列表中充满了尚未清理的自动生成的代码,您可以使用FIXME
、XXX
或定义您自己的代码。然后您应该能够过滤您的列表。Based on your original question and comments, I assume you're trying to do the following:
I don't believe you can mark the code with a compiler warning. The
@Deprecated
tag is baked into the compiler. A more common way of indicating a method is incomplete is by throwing an exception:throw new UnsupportedOperationException("Not implemented yet");
The effect isn't realized until runtime, but the other developers should be unit testing their code.
As for identifying the incomplete code I would still refer back to my original comment. Use the
TODO
comment tag and Eclipse will build a task list for you. If your list is cluttered with auto-generated code that hasn't been cleaned up, you can useFIXME
,XXX
, or define your own. You should then be able to filter your list.我已要求龙目岛人民考虑提供此功能 https://github.com/ peichhorn/lombok-pg/issues/114 现已实施;-) https://github.com/peichhorn/lombok-pg/wiki/%40Warning
I've asked the Lombok people to look at providing this functionality https://github.com/peichhorn/lombok-pg/issues/114 and it is now implemented ;-) https://github.com/peichhorn/lombok-pg/wiki/%40Warning
可以通过注释处理器 api
这是轻量级 Javac 警告注释库 https://github.com/pushtorefresh/ javac-warning-annotation
用法:
It's possible via annotation processors api
Here is Lightweight Javac Warning Annotation library https://github.com/pushtorefresh/javac-warning-annotation
Usage: