forked from phoedos/pmd
new rule AvoidLiteralsInIfCondition added to controversial ruleset
Patch contributed by Nadhamuni Kothapalle https://sourceforge.net/tracker/?func=detail&atid=479923&aid=2591627&group_id=56262 git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6888 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -6,6 +6,7 @@ Fixed bug 2606609 - False "UnusedImports" positive in package-info.java
|
||||
Fixed bug 2645268 - ClassCastException in UselessOperationOnImmutable.getDeclaration
|
||||
|
||||
New rule:
|
||||
Controversial : AvoidLiteralsInIfCondition (patch 2591627)
|
||||
StrictExceptions : AvoidCatchingGenericException
|
||||
|
||||
February 08, 2009 - 4.2.5:
|
||||
|
@ -10,6 +10,7 @@ public class ControversialRulesTest extends SimpleAggregatorTst {
|
||||
public void setUp() {
|
||||
addRule("controversial", "AssignmentInOperand");
|
||||
addRule("controversial", "AvoidFinalLocalVariable");
|
||||
addRule("controversial", "AvoidLiteralsInIfCondition");
|
||||
addRule("controversial", "AvoidUsingNativeCode");
|
||||
addRule("controversial", "AvoidUsingShortType");
|
||||
addRule("controversial", "AvoidUsingVolatile");
|
||||
|
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<test-code>
|
||||
<description>basic test</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class PrimitiveType {
|
||||
public void downCastPrimitiveType() {
|
||||
if(i==1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>basic test, part2</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class PrimitiveType {
|
||||
public static final int PRIMITIVE_TYPE = 1;
|
||||
public void downCastPrimitiveType() {
|
||||
if(i==PRIMITIVE_TYPE) {
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
@ -682,6 +682,36 @@ public void doSomething() { // Explicit gc call ! Runtime.getRuntime().gc(); } }
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AvoidLiteralsInIfCondition"
|
||||
since="4.2.6"
|
||||
message="Avoid using Literals in Conditional Statements"
|
||||
class="net.sourceforge.pmd.rules.XPathRule"
|
||||
externalInfoUrl="http://pmd.sourceforge.net/rules/controversial.html#AvoidLiteralsInIfCondition">
|
||||
<description>
|
||||
Avoid using hard coded literals in conditional statements, declare those as static variables or private members.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement/Expression/*/PrimaryExpression/PrimaryPrefix/Literal
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class PrimitiveType {
|
||||
public void downCastPrimitiveType() {
|
||||
if(i==1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user