告诉 IntelliJ IDEA 哪些方法不被识别为未使用 [英] Telling IntelliJ IDEA which methods not to identify as unused

查看:69
本文介绍了告诉 IntelliJ IDEA 哪些方法不被识别为未使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IntelliJ IDEA 有一个方便的功能,可以检测未使用的方法并将它们显示为灰色,提示潜在的死代码警告.

IntelliJ IDEA has a handy feature to detect unused methods and show them in grey, hinting a potential warning for dead code.

然而,有些方法不是直接执行的,而是通过反射执行的.一个很好的例子是由 Spring 执行的 @RequestMapping 注释方法.IntelliJ 具有不错的 Spring 集成,因此它会检测此注释并且不会将此类方法标记为未使用.

Some methods, however, are not executed directly but via reflection. A good example would be @RequestMapping-annotated methods which are executed by Spring. IntelliJ has decent Spring integration hence it detects this annotation and does not mark such a method as unused.

我有一个很小的 ​​AJAX 框架,我使用自己的注释根据某些 HTTP 请求属性指出要执行的方法(与 @RequestMapping 所做的非常相似).可以理解的是,IntelliJ 不知道我的注释代表什么,并将这种方法标记为未使用,从而增加了不必要的噪音.

I have a tiny AJAX framework where I use my own annotation to point which method to execute based on certain HTTP request properties (very similar to what @RequestMapping is doing). Understandably, IntelliJ has no idea what does my annotation stand for and and marks such a method as unused, adding unnecessary noise.

我在想:

  • 使用另一个注释来注释我的注释,但是否有任何标准的注释可以无需任何额外工作即可完成这项工作?
  • 在 IntelliJ 中找到一个特定的设置来识别用于标记方法的自定义注释,但这需要其他团队成员做同样的事情,基本上很痛苦.

任何人都可以提出任何解决此问题的想法吗?

Can anyone suggest any ideas how to solve this problem?

推荐答案

您可以告诉 IntelliJ 对于使用未使用"方法所具有的注释的任何方法/字段不发出警告.

You can tell IntelliJ to not to warn about used for any method/field annotated with the annotation the "unused" method has.

这应该是一个快速解决方法,您只需点击 <Alt>+<Enter> 并选择 Suppress for annotated by ...

It should be a quick fix all you have to do is hit <Alt>+<Enter> and select Suppress for methods annotated by ...

您无需在代码中添加任何内容,每个注释只需添加一次.

You don't need to add anything to you code and you only have to do this once per annotation.

这篇关于告诉 IntelliJ IDEA 哪些方法不被识别为未使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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