使用用户定义的注释生成编译器警告 [英] Generate compiler warning with user defined annotation

查看:24
本文介绍了使用用户定义的注释生成编译器警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让编译器在遇到用户定义的注释时生成警告?类似于 @Deprecated 注释?

Is it possible for make the compiler generate a warning when it encounters a user defined annotaion? Something similar to the @Deprecated annotation?

谢谢

推荐答案

根据您的原始问题和评论,我假设您正在尝试执行以下操作:

Based on your original question and comments, I assume you're trying to do the following:

  • 将代码标记为不完整(带有编译器警告),以免其他开发人员使用它.
  • 稍后确定 IDE 中不完整的代码.

我不相信您可以用编译器警告标记代码.@Deprecated 标签被嵌入到编译器中.一种更常见的表示方法不完整的方法是抛出异常:

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("尚未实现");

直到运行时才会实现效果,但其他开发人员应该对他们的代码进行单元测试.

The effect isn't realized until runtime, but the other developers should be unit testing their code.

至于识别不完整的代码,我仍然会参考我原来的评论.使用 TODO 注释标记,Eclipse 将为您构建一个任务列表.如果您的列表中充斥着尚未清理的自动生成代码,您可以使用 FIXMEXXX 或定义您自己的代码.然后,您应该能够过滤您的列表.

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 use FIXME, XXX, or define your own. You should then be able to filter your list.

这篇关于使用用户定义的注释生成编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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