[英]Ignore all checkstyle warnings for deprecated classes and methods
Can I somehow ignore any warning for deprecated class? 我可以以某种方式忽略有关已弃用课程的任何警告吗?
For example: 例如:
I had following warnings AvoidEscapedUnicodeCharacters
, NonEmptyAtclauseDescription
for deprecated class. 对于已弃用的类,我有以下警告
AvoidEscapedUnicodeCharacters
, NonEmptyAtclauseDescription
。
How to ignore all of them? 如何忽略所有这些?
Checkstyle allows you to write your own custom filters . Checkstyle允许您编写自己的自定义过滤器 。 You can use
SuppressWarningsFilter
as a basis, because this filter is filtering based on annotations as well. 您可以使用
SuppressWarningsFilter
作为基础,因为此过滤器也基于注释进行过滤。 You'd just need to change the annotation that you're looking for. 您只需要更改要查找的注释即可。
public class SuppressWarningsFilter
extends AutomaticBean
implements Filter {
@Override
protected void finishLocalSetup() {
// No code by default
}
@Override
public boolean accept(AuditEvent event) {
return !SuppressWarningsHolder.isSuppressed(event);
}
}
Pretty simple, but all of the logic is in SuppressWarningsHolder
. 非常简单,但是所有逻辑都在
SuppressWarningsHolder
。 That code is a few hundred lines, but you should be able to copy and paste a lot of it, and probably remove a large chuck as well. 该代码只有几百行,但是您应该能够复制并粘贴很多代码,并且还可以删除一个大的卡盘。
I've implemented this: https://github.com/michaelboyles/checkstyle-annotation-filter . 我已经实现了这一点: https : //github.com/michaelboyles/checkstyle-annotation-filter 。 I'll make it available via the central repository at some point.
我将在某个时候通过中央存储库使它可用。
You just need to add the line below: 您只需要添加以下行:
@SuppressWarnings("deprecation")
It will ignore all deprecated methods in your code. 它将忽略代码中所有不推荐使用的方法。 I hope this will help.
我希望这将有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.