From 320e5289a3c1e707698db03fc5e01449ef619585 Mon Sep 17 00:00:00 2001 From: Allan Caplan Date: Mon, 9 Oct 2006 00:11:23 +0000 Subject: [PATCH] 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 --- pmd/etc/changelog.txt | 1 + .../rules/BigIntegerInstantiationTest.java | 51 +++++++++++ pmd/rulesets/basic.xml | 86 +++++++++++++++++++ pmd/rulesets/releases/39.xml | 10 +++ pmd/xdocs/credits.xml | 2 +- 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/BigIntegerInstantiationTest.java create mode 100644 pmd/rulesets/releases/39.xml diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 4fbecb21e0..d96881f4f5 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -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. diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/BigIntegerInstantiationTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/BigIntegerInstantiationTest.java new file mode 100644 index 0000000000..37b89764ac --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/BigIntegerInstantiationTest.java @@ -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 + + "}"; + + +} diff --git a/pmd/rulesets/basic.xml b/pmd/rulesets/basic.xml index c3f68fc481..304db5958a 100644 --- a/pmd/rulesets/basic.xml +++ b/pmd/rulesets/basic.xml @@ -1003,5 +1003,91 @@ class Foo { + + +Don't create instances of already existing BigInteger +(BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN) +and BigDecimal (BigDecimal.ZERO, BigDecimal.ONE, +BigDecimal.TEN) + + + + + + + + + 3 + + + + + + + +Don't create instances of already existing BigInteger +(BigInteger.ZERO, BigInteger.ONE) + + + + + + + + + 3 + + + + diff --git a/pmd/rulesets/releases/39.xml b/pmd/rulesets/releases/39.xml new file mode 100644 index 0000000000..ec4707c347 --- /dev/null +++ b/pmd/rulesets/releases/39.xml @@ -0,0 +1,10 @@ + + + + +This ruleset contains links to rules that are new in PMD v3.9 + + + + diff --git a/pmd/xdocs/credits.xml b/pmd/xdocs/credits.xml index ae21c5dded..7b402aafe1 100644 --- a/pmd/xdocs/credits.xml +++ b/pmd/xdocs/credits.xml @@ -101,7 +101,7 @@
  • Erik Thauvin - reported IDEA integration problem
  • John Kenny - reported bug in ConsecutiveLiteralAppends
  • 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
  • -
  • Fabio Insaccanebbia - UnusedNullCheckInEquals, MisplacedNullCheck, UselessOperationOnImmutable, AvoidArrayLoops, UseArraysAsList, AvoidConstantsInterface, AvoidDecimalLiteralsInBigDecimalConstructor, ClassCastExceptionWithToArray
  • +
  • Fabio Insaccanebbia - UnusedNullCheckInEquals, MisplacedNullCheck, UselessOperationOnImmutable, AvoidArrayLoops, UseArraysAsList, AvoidConstantsInterface, AvoidDecimalLiteralsInBigDecimalConstructor, ClassCastExceptionWithToArray, BigIntegerInstantiation_1.4, BigIntegerInstantiation_1.5
  • Sean Mountcastle - reported documentation bug
  • Greg Broderick - provided patch for 'minimum priority' support
  • George Sexton - Bug report 1379701 for CompareObjectsWithEquals, suggested new rule for Additional String Concatenation Warnings in StringBuffer.