From fd9b9b6e3e2bbb32e4163b8945cb8135d1243cdf Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Wed, 14 Dec 2005 14:44:58 +0000 Subject: [PATCH] Added Fabio Insaccanebbia's implementation of AvoidConstantsInterface; thx Fabio! git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4063 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 7 ++-- .../design/AvoidConstantsInterfaceTest.java | 36 +++++++++++++++++++ pmd/rulesets/design.xml | 32 +++++++++++++++++ pmd/xdocs/credits.xml | 2 +- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/design/AvoidConstantsInterfaceTest.java diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 8549438f8b..712a270762 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -3,6 +3,7 @@ New rules: Migration ruleset: IntegerInstantiation JUnit ruleset: UseAssertNullInsteadOfAssertTrue Strings ruleset: AppendCharacterWithChar + Design ruleset: AvoidConstantsInterface Fixed bug 1277373 - InefficientStringBuffering now catches more cases. Fixed bug 1371757 - Misleading example in AvoidSynchronizedAtMethodLevel Fixed bug 1371980 - InefficientStringBuffering no longer flags StringBuffer methods other than append(). @@ -20,8 +21,10 @@ Modified renderers to support disabling printing of suppressed warnings. Introd Added current CLASSPATH to pmd.bat. UnusedFormalParameter now catches unused constructor parameters, and its warning message now reflects whether it caught a method or a constructor param. Rebuilt JavaCC parser with JavaCC 4.0beta1. -Added David Corley's Javascript report, more details are here: http://tomcopeland.blogs.com/juniordeveloper/2005/12/demo_of_some_ni.html -TODO: Removed old-style CPD command line options that were deprecated in 3.4. +Added David Corley's Javascript report, more details are here: http://tomcopeland.blogs.com/juniordeveloper/2005/12/demo_of_some_ni.html + +***** TODO: Remove old-style CPD command line options that were deprecated in 3.4. +***** TODO: Remove deprecated RuleViolation.getLine() November 30, 2005 - 3.4: New rules: diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/design/AvoidConstantsInterfaceTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/design/AvoidConstantsInterfaceTest.java new file mode 100644 index 0000000000..2824c21195 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/design/AvoidConstantsInterfaceTest.java @@ -0,0 +1,36 @@ +package test.net.sourceforge.pmd.rules.design; + +import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; +import test.net.sourceforge.pmd.testframework.TestDescriptor; +import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.RuleSetNotFoundException; +import net.sourceforge.pmd.PMD; + +public class AvoidConstantsInterfaceTest extends SimpleAggregatorTst { + + private Rule rule; + + public void setUp() throws RuleSetNotFoundException { + rule = findRule("design", "AvoidConstantsInterface"); + } + + public void testAll() { + runTests(new TestDescriptor[] { + new TestDescriptor(TEST1, "clear rule violation", 1, rule), + new TestDescriptor(TEST2, "ok", 0, rule), + }); + } + + private static final String TEST1 = + "public interface Foo {" + PMD.EOL + + " public static final int FOO = 2;" + PMD.EOL + + " public static final String BAR = \"bar\";" + PMD.EOL + + "}"; + + private static final String TEST2 = + "public interface Foo {" + PMD.EOL + + " public static final int FOO = 2;" + PMD.EOL + + " public void buz();" + PMD.EOL + + "}"; + +} diff --git a/pmd/rulesets/design.xml b/pmd/rulesets/design.xml index 9c1700593b..595505734c 100644 --- a/pmd/rulesets/design.xml +++ b/pmd/rulesets/design.xml @@ -1213,4 +1213,36 @@ public Foo() { + + + An interface should be used only to model a behaviour of a + class: using an interface as a container of constants is a poor usage pattern. + + + + + 0 + ] + ]]> + + + + 3 + + + + + diff --git a/pmd/xdocs/credits.xml b/pmd/xdocs/credits.xml index 0ecd0193c2..feb6782254 100644 --- a/pmd/xdocs/credits.xml +++ b/pmd/xdocs/credits.xml @@ -45,6 +45,7 @@