PMD xpath to suppress AtLeastOneConstructor and UnusedPrivateField?

こ雲淡風輕ζ 提交于 2019-12-21 05:45:12

问题


I have this piece of code and PMD reports two rule violations:

AbstractExceptionHandler has no constructor (AtLeastOneConstructor)

And the field uriInfo is a unused private field (UnusedPrivateField)

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

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

both warnings are okay, but we use annotations to generate code. So the warning is useless for us.

We have created following suppressions:

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>

And the PMD xpath Designer tells us it is the exact used lines with the violation, but still PMD reports a error. Can someone help me out of the dark?

来源:https://stackoverflow.com/questions/28604905/pmd-xpath-to-suppress-atleastoneconstructor-and-unusedprivatefield

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!