forked from phoedos/pmd
Implemented patch 1377773 - UseMathConstants From Fabio
Renamed rule(s) to BigIntegerInstantiation to maintain consistency with BooleanInstantiation, placed in basic ruleset. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4600 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
?????, 2006 - 3.9:
|
||||
New rules:
|
||||
Basic ruleset: BigIntegerInstantiation(1.4 and 1.5)
|
||||
SummaryHTML Report changes from Brent Fisher - now contains linePrefix to support source output from javadoc using "linksource"
|
||||
Fixed bug 1570915 - AvoidRethrowingException no longer reports a false positive for certain nested exceptions.
|
||||
Fixed bug 1571324 - UselessStringValueOf no longer reports a false positive for additive expressions.
|
||||
|
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package test.net.sourceforge.pmd.rules;
|
||||
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
import test.net.sourceforge.pmd.testframework.TestDescriptor;
|
||||
|
||||
public class BigIntegerInstantiationTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule14;
|
||||
private Rule rule15;
|
||||
|
||||
public void setUp() throws RuleSetNotFoundException {
|
||||
rule14 = findRule("basic", "BigIntegerInstantiation_1.4");
|
||||
rule15 = findRule("basic", "BigIntegerInstantiation_1.5");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[]{
|
||||
new TestDescriptor(TEST1, "Fail, BigInteger(1)", 1, rule14),
|
||||
new TestDescriptor(TEST2, "Pass, BigInteger(10)", 0, rule14),
|
||||
new TestDescriptor(TEST3, "Fail, BigInteger(0)", 1, rule14),
|
||||
});
|
||||
runTests(new TestDescriptor[]{
|
||||
new TestDescriptor(TEST1, "Fail, BigInteger(1)", 1, rule15),
|
||||
new TestDescriptor(TEST2, "Fail, BigInteger(10)", 1, rule15),
|
||||
new TestDescriptor(TEST3, "Fail, BigInteger(0)", 1, rule15),
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" BigInteger b = new BigInteger(1);" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String TEST2 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" BigInteger b = new BigInteger(10);" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String TEST3 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" BigInteger b = new BigInteger(0);" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
|
||||
}
|
@ -1003,5 +1003,91 @@ class Foo {
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="BigIntegerInstantiation_1.5"
|
||||
message="Don't create instances of already existing
|
||||
BigInteger and BigDecimal (ZERO, ONE, TEN)"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Don't create instances of already existing BigInteger
|
||||
(BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN)
|
||||
and BigDecimal (BigDecimal.ZERO, BigDecimal.ONE,
|
||||
BigDecimal.TEN)
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//Expression[./PrimaryExpression/PrimaryPrefix/AllocationExpression[./ClassOrInterfaceType[@Image="BigInteger"
|
||||
or
|
||||
@Image="BigDecimal"]]/Arguments/ArgumentList[count(./Expression)=1]/Expression/PrimaryExpression/PrimaryPrefix/Literal[@Image=1
|
||||
or @Image='"1"' or @Image=0 or
|
||||
@Image='"0"' or @Image=10 or
|
||||
@Image='"10"']]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BigInteger bi=new BigInteger(1);
|
||||
|
||||
BigInteger bi2=new BigInteger(0);
|
||||
|
||||
BigInteger bi3=new BigInteger(10);
|
||||
|
||||
BigDecimal bd=new BigDecimal(1);
|
||||
|
||||
BigDecimal bd2=new BigDecimal(0);
|
||||
|
||||
BigDecimal bd3=new BigDecimal(10);
|
||||
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="BigIntegerInstantiation_1.4"
|
||||
message="Don't create instances of already existing
|
||||
BigInteger (BigInteger.ZERO, BigInteger.ONE)"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Don't create instances of already existing BigInteger
|
||||
(BigInteger.ZERO, BigInteger.ONE)
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//Expression[./PrimaryExpression/PrimaryPrefix/AllocationExpression[./ClassOrInterfaceType[@Image="BigInteger"]]/Arguments/ArgumentList[count(./Expression)=1]/Expression/PrimaryExpression/PrimaryPrefix/Literal[@Image=1
|
||||
or @Image='"1"' or @Image=0 or
|
||||
@Image='"0"']]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BigInteger bi=new BigInteger(1);
|
||||
|
||||
BigInteger bi2=new BigInteger("0");
|
||||
|
||||
BigInteger bi3=new BigInteger(0.0);
|
||||
|
||||
BigInteger bi4;
|
||||
bi4=new BigInteger(0);
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</ruleset>
|
||||
|
||||
|
10
pmd/rulesets/releases/39.xml
Normal file
10
pmd/rulesets/releases/39.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="38" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
|
||||
<description>
|
||||
This ruleset contains links to rules that are new in PMD v3.9
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/basic.xml/BigIntegerInstantiation_1.5"/>
|
||||
</ruleset>
|
@ -101,7 +101,7 @@
|
||||
<li>Erik Thauvin - reported IDEA integration problem</li>
|
||||
<li>John Kenny - reported bug in ConsecutiveLiteralAppends</li>
|
||||
<li>Tom Judge - patch for fix to C/C++ multiline literal support for CPD, patch for including .cc files in C++ CPD checks, patch for JDK compatibility problems</li>
|
||||
<li><a href="http://www.livejournal.com/users/insac/">Fabio Insaccanebbia</a> - UnusedNullCheckInEquals, MisplacedNullCheck, UselessOperationOnImmutable, AvoidArrayLoops, UseArraysAsList, AvoidConstantsInterface, AvoidDecimalLiteralsInBigDecimalConstructor, ClassCastExceptionWithToArray</li>
|
||||
<li><a href="http://www.livejournal.com/users/insac/">Fabio Insaccanebbia</a> - UnusedNullCheckInEquals, MisplacedNullCheck, UselessOperationOnImmutable, AvoidArrayLoops, UseArraysAsList, AvoidConstantsInterface, AvoidDecimalLiteralsInBigDecimalConstructor, ClassCastExceptionWithToArray, BigIntegerInstantiation_1.4, BigIntegerInstantiation_1.5</li>
|
||||
<li>Sean Mountcastle - reported documentation bug</li>
|
||||
<li>Greg Broderick - provided patch for 'minimum priority' support</li>
|
||||
<li>George Sexton - Bug report 1379701 for CompareObjectsWithEquals, suggested new rule for Additional String Concatenation Warnings in StringBuffer.</li>
|
||||
|
Reference in New Issue
Block a user