Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何告诉PMD忽略未使用代码的@PostConstruct方法_Java_Ejb_Cdi_Pmd - Fatal编程技术网

Java 如何告诉PMD忽略未使用代码的@PostConstruct方法

Java 如何告诉PMD忽略未使用代码的@PostConstruct方法,java,ejb,cdi,pmd,Java,Ejb,Cdi,Pmd,我们有一个项目,PMD检查该项目是否违反了未使用的私有方法。我们的问题是,我们不知道是否可以忽略用@PostConstruct注释的私有方法 该规则定义如下: <rule ref="rulesets/java/unusedcode.xml/UnusedPrivateMethod"/> 编辑: 我的目标是定义它一次以忽略带注释的方法。我想阻止在每个方法上写入@superswarnings。在HairyFort的提示和建议下,我可以将规则集配置为忽略@PostConstruct的私


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

该规则定义如下:

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

编辑:
我的目标是定义它一次以忽略带注释的方法。我想阻止在每个方法上写入
@superswarnings

在HairyFort的提示和建议下,我可以将规则集配置为忽略
@PostConstruct
私有方法

我必须使用的规则是:

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

只要至少存在一个@PostConstruct注释,就会抑制文件中所有未使用的PrivateMethod冲突。如果您只想抑制来自带有@PostConstruct注释的方法的冲突,并保留来自不带注释的方法的冲突,那么您必须使用
祖先::
而不是
/
预加XPath

注意:下面的示例使用PMD 6.0.0的新规则引用

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

我认为该值需要以双斜杠(“/”)而不是双冒号(“:”)开头。