Support Boolean wrapper class for BooleanGetMethodName rule (#5253)
This commit is contained in:
@ -172,32 +172,33 @@ public class SomeJNIClass {
|
|||||||
<rule name="BooleanGetMethodName"
|
<rule name="BooleanGetMethodName"
|
||||||
language="java"
|
language="java"
|
||||||
since="4.0"
|
since="4.0"
|
||||||
message="A 'getX()' method which returns a boolean should be named 'isX()'"
|
message="A 'getX()' method which returns a boolean or Boolean should be named 'isX()'"
|
||||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#booleangetmethodname">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#booleangetmethodname">
|
||||||
<description>
|
<description>
|
||||||
Methods that return boolean results should be named as predicate statements to denote this.
|
Methods that return boolean or Boolean results should be named as predicate statements to denote this.
|
||||||
I.e, 'isReady()', 'hasValues()', 'canCommit()', 'willFail()', etc. Avoid the use of the 'get'
|
I.e., 'isReady()', 'hasValues()', 'canCommit()', 'willFail()', etc. Avoid the use of the 'get' prefix for these methods.
|
||||||
prefix for these methods.
|
|
||||||
</description>
|
</description>
|
||||||
<priority>4</priority>
|
<priority>4</priority>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
<value>
|
<value>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
//MethodDeclaration
|
//MethodDeclaration
|
||||||
[starts-with(@Name, 'get')]
|
[starts-with(@Name, 'get')]
|
||||||
[@Arity = 0 or $checkParameterizedMethods = true()]
|
[@Arity = 0 or $checkParameterizedMethods = true()]
|
||||||
[ PrimitiveType[@Kind = 'boolean'] and @Overridden = false() ]
|
[ (PrimitiveType[@Kind = 'boolean'] or ReferenceType[@Type = 'Boolean']) and @Overridden = false() ]
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
<property name="checkParameterizedMethods" type="Boolean" description="Check parameterized methods" value="false"/>
|
<property name="checkParameterizedMethods" type="Boolean" description="Check parameterized methods" value="false"/>
|
||||||
</properties>
|
</properties>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
public boolean getFoo(); // bad
|
public boolean getFoo(); // bad
|
||||||
|
public Boolean getFoo(); // bad
|
||||||
public boolean isFoo(); // ok
|
public boolean isFoo(); // ok
|
||||||
|
public Boolean isFoo(); // ok
|
||||||
public boolean getFoo(boolean bar); // ok, unless checkParameterizedMethods=true
|
public boolean getFoo(boolean bar); // ok, unless checkParameterizedMethods=true
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
|
Reference in New Issue
Block a user