如何告诉PMD忽略@PostConstruct方法来使用未使用的代码 [英] How to tell PMD to ignore @PostConstruct Methods for unused Code

查看:783
本文介绍了如何告诉PMD忽略@PostConstruct方法来使用未使用的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们有一个由PMD检查的项目,例如违反。未使用的私有方法我们的问题是,我们不知道是否可以忽略使用 @PostConstruct 注释的私有方法。

规则定义如下:

<rule ref="rulesets/java/unusedcode.xml/UnusedPrivateMethod"/>



编辑:



我的目标是定义一次以忽略注释方法。我想防止在每个方法上写 @SupressWarnings

推荐答案

有了HairyFotr的提示和建议,我可以配置我的规则集以忽略 private 方法与 @PostConstruct

With the hint and advice from HairyFotr i was able to configure my ruleset to ignore private methods with @PostConstruct.

我必须使用的规则是:

<rule ref="rulesets/java/unusedcode.xml/UnusedPrivateMethod">
    <properties> 
        <property name="violationSuppressXPath" 
            value="//ClassOrInterfaceBodyDeclaration/Annotation/MarkerAnnotation/Name[@Image='PostConstruct']" />
    </properties>
</rule>   

这篇关于如何告诉PMD忽略@PostConstruct方法来使用未使用的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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