PMD xpath抑制AtLeastOneConstructor和UnusedPrivateField?

时间:2015-02-19 11:13:50

标签: xpath pmd

我有这段代码而PMD报告了两条规则违规行为:

AbstractExceptionHandler没有构造函数(AtLeastOneConstructor)

字段uriInfo是未使用的私有字段(UnusedPrivateField)

@NoArgsConstructor
public class AbstractExceptionHandler {  // PMD AtLeastOneConstructor warning here 

   /** the uriInfo injection. */
   @Getter
   @Context
   private UriInfo uriInfo; // PMD UnusedPrivateField warning here

两个警告都没问题,但我们使用注释来生成代码。所以警告对我们来说毫无用处。

我们创建了以下抑制:

AtLeastOneConstructor

<rule ref="rulesets/java/controversial.xml/AtLeastOneConstructor">
    <properties>
        <property name="violationSuppressXPath"
            value="//ClassOrInterfaceDeclaration[//ImportDeclaration//Name[@Image='lombok.NoArgsConstructor'] | //TypeDeclaration//MarkerAnnotation//Name[@Image='NoArgsConstructor']]" />
    </properties>
</rule>

UnusedPrivateField

<rule ref="rulesets/java/unusedcode.xml/UnusedPrivateField">
    <properties>
        <property name="violationSuppressXPath"
            value="//ClassOrInterfaceBodyDeclaration//FieldDeclaration[//TypeDeclaration//MarkerAnnotation//Name[@Image='Getter'] | //TypeDeclaration//MarkerAnnotation//Name[@Image='Setter']]"/>
    </properties>
</rule>

PMD xpath Designer告诉我们它是违规的确切使用行,但PMD仍报告错误。 有人可以帮助我摆脱黑暗吗?

0 个答案:

没有答案