From 30063d0b33243f3a9ee8d4b4fd603674dc806c35 Mon Sep 17 00:00:00 2001 From: Allan Caplan Date: Thu, 1 Feb 2007 02:10:53 +0000 Subject: [PATCH] RFE 1562230 - New Rules as IntegerInstantiation for Byte, Short, Long Request had recomended XPath which worked very well. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5027 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../migrating/ByteInstantiationTest.java | 17 ++++ .../migrating/LongInstantiationTest.java | 17 ++++ .../migrating/ShortInstantiationTest.java | 17 ++++ .../rules/migrating/xml/ByteInstantiation.xml | 29 +++++++ .../rules/migrating/xml/LongInstantiation.xml | 29 +++++++ .../migrating/xml/ShortInstantiation.xml | 29 +++++++ pmd/rulesets/migrating.xml | 85 +++++++++++++++++++ pmd/rulesets/migrating_to_15.xml | 3 + pmd/rulesets/releases/40.xml | 13 +++ pmd/xdocs/credits.xml | 1 + 11 files changed, 241 insertions(+) create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/migrating/ByteInstantiationTest.java create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/migrating/LongInstantiationTest.java create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/migrating/ShortInstantiationTest.java create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/ByteInstantiation.xml create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/LongInstantiation.xml create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/ShortInstantiation.xml create mode 100644 pmd/rulesets/releases/40.xml diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index a21bcb9c5c..10ef6d4924 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -9,6 +9,7 @@ Fixed bug 1631646 - UselessOperationOnImmutable doesn't throw on variable.method Fixed bug 1627830 - UseLocaleWithCaseConversions now works with compound string operations Fixed bug 1613807 - DontImportJavaLang rule allows import to Thread inner classes Applied patch 1612455 - RFE 1411022 CompareObjectsWithEquals now catches the case where comparison is against new Object +Implemented RFE 1562230 - Added migration rule to check for instantiation of Short/Byte/Long Implemented RFE 1627581 - SuppressWarnings("unused") now suppresses all warnings in unusedcode.xml XPath rules are now chained together for an extra speedup in processing PMD now requires JDK 1.5 to be compiled. Java 1.4 support is provided using Retroweaver diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/migrating/ByteInstantiationTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/ByteInstantiationTest.java new file mode 100644 index 0000000000..d0d1b29310 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/ByteInstantiationTest.java @@ -0,0 +1,17 @@ +package test.net.sourceforge.pmd.rules.migrating; + +import net.sourceforge.pmd.Rule; +import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; + +public class ByteInstantiationTest extends SimpleAggregatorTst { + + private Rule rule; + + public void setUp() { + rule = findRule("migrating", "ByteInstantiation"); + } + + public void testAll() { + runTests(rule); + } +} diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/migrating/LongInstantiationTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/LongInstantiationTest.java new file mode 100644 index 0000000000..82deff97d1 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/LongInstantiationTest.java @@ -0,0 +1,17 @@ +package test.net.sourceforge.pmd.rules.migrating; + +import net.sourceforge.pmd.Rule; +import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; + +public class LongInstantiationTest extends SimpleAggregatorTst { + + private Rule rule; + + public void setUp() { + rule = findRule("migrating", "LongInstantiation"); + } + + public void testAll() { + runTests(rule); + } +} diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/migrating/ShortInstantiationTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/ShortInstantiationTest.java new file mode 100644 index 0000000000..20c3989164 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/ShortInstantiationTest.java @@ -0,0 +1,17 @@ +package test.net.sourceforge.pmd.rules.migrating; + +import net.sourceforge.pmd.Rule; +import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; + +public class ShortInstantiationTest extends SimpleAggregatorTst { + + private Rule rule; + + public void setUp() { + rule = findRule("migrating", "ShortInstantiation"); + } + + public void testAll() { + runTests(rule); + } +} diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/ByteInstantiation.xml b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/ByteInstantiation.xml new file mode 100644 index 0000000000..1a3f297af7 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/ByteInstantiation.xml @@ -0,0 +1,29 @@ + + + + + 1 + + + + + 0 + + + \ No newline at end of file diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/LongInstantiation.xml b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/LongInstantiation.xml new file mode 100644 index 0000000000..79b7caf6e9 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/LongInstantiation.xml @@ -0,0 +1,29 @@ + + + + + 1 + + + + + 0 + + + \ No newline at end of file diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/ShortInstantiation.xml b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/ShortInstantiation.xml new file mode 100644 index 0000000000..1da9349f0c --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/migrating/xml/ShortInstantiation.xml @@ -0,0 +1,29 @@ + + + + + 1 + + + + + 0 + + + \ No newline at end of file diff --git a/pmd/rulesets/migrating.xml b/pmd/rulesets/migrating.xml index a9e880fe0b..210ec8d3f1 100644 --- a/pmd/rulesets/migrating.xml +++ b/pmd/rulesets/migrating.xml @@ -177,6 +177,91 @@ public class Foo { ]]> + + + In JDK 1.5, calling new Byte() causes memory allocation. Byte.valueOf() is more memory friendly. + + + + + + + + + 2 + + + + + + + In JDK 1.5, calling new Short() causes memory allocation. Short.valueOf() is more memory friendly. + + + + + + + + + 2 + + + + + + + In JDK 1.5, calling new Long() causes memory allocation. Long.valueOf() is more memory friendly. + + + + + + + + 2 + + + + diff --git a/pmd/rulesets/migrating_to_15.xml b/pmd/rulesets/migrating_to_15.xml index e50a7c2c22..0659ca9cfb 100644 --- a/pmd/rulesets/migrating_to_15.xml +++ b/pmd/rulesets/migrating_to_15.xml @@ -11,6 +11,9 @@ Contains rules for migrating to JDK 1.5 + + + diff --git a/pmd/rulesets/releases/40.xml b/pmd/rulesets/releases/40.xml new file mode 100644 index 0000000000..386ca14ade --- /dev/null +++ b/pmd/rulesets/releases/40.xml @@ -0,0 +1,13 @@ + + + + +This ruleset contains links to rules that are new in PMD v4.0 + + + + + + + \ No newline at end of file diff --git a/pmd/xdocs/credits.xml b/pmd/xdocs/credits.xml index e82c7adf68..40e50d402e 100644 --- a/pmd/xdocs/credits.xml +++ b/pmd/xdocs/credits.xml @@ -297,6 +297,7 @@
  • Ebu - Eclipse smoothed icons
  • Jacques Lebourgeois - Eclipse fix malformed UTF-8 characters
  • Chris Grindstaff - Eclipse fix SWTException when PMD is run on a file with syntax error
  • +
  • jmichelberger - wrote Byte/Short/Long Instantiation migration rules