Support wrapper class in BooleanGetMethodName rule (#5253)\n \n - Updated XPath rule to include both primitive and wrapper class:\n (PrimitiveType[@Kind = 'boolean'] or ClassType[pmd-java:typeIs('java.lang.Boolean')])\n - Added test cases to ensure that methods returning are also flagged correctly.\n - Ensured the rule enforces consistent method naming for both primitive and wrapper types.
This commit is contained in:
parent
8b2af2db8a
commit
ed6312e3ba
@ -35,11 +35,13 @@ public class Foo {
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Should not match on multiple parameters by default</description>
|
||||
<description>Should not match for boxed Boolean on multiple parameters by default (#5253)</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public Boolean getEnabled(boolean thisIsNotABean);
|
||||
public Boolean getEnabled(boolean thisIsNotABean) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
@ -72,11 +74,13 @@ public class Foo {
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Bad name</description>
|
||||
<description>Bad name with boxed Boolean (#5253)</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public Boolean getEnabled();
|
||||
public Boolean getEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
@ -86,13 +90,15 @@ public class Foo {
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public Boolean isEnabled();
|
||||
public Boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Should not match on methods annotated with @Override</description>
|
||||
<description>Should not match for boxed Boolean on methods annotated with @Override (#5253)</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo implements Toggleable {
|
||||
@ -107,10 +113,8 @@ interface Toggleable {
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
|
||||
|
||||
<test-code>
|
||||
<description>Should match on multiple parameters when checkParameterizedMethods = true</description>
|
||||
<description>Should match for boxed Boolean on multiple parameters when checkParameterizedMethods = true (#5253)</description>
|
||||
<rule-property name="checkParameterizedMethods">true</rule-property>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
@ -120,4 +124,41 @@ public class Foo {
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Should match for boxed Boolean on multiple parameters when checkParameterizedMethods = true (#5253)</description>
|
||||
<rule-property name="checkParameterizedMethods">true</rule-property>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public Boolean getEnabled(boolean thisIsNotABean) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Custom Boolean type (#5253)</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
class Boolean { }
|
||||
public class Foo {
|
||||
public Boolean getEnabled() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Custom Boolean type with returning value (#5253)</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
class Boolean { }
|
||||
public class Foo {
|
||||
public Boolean getEnabled() { return false; }
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
</test-data>
|
||||
|
Loading…
x
Reference in New Issue
Block a user