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
This commit is contained in:
Tom Copeland
2005-12-14 14:44:58 +00:00
parent f75ad93b2c
commit fd9b9b6e3e
4 changed files with 74 additions and 3 deletions

View File

@ -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:

View File

@ -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 +
"}";
}

View File

@ -1213,4 +1213,36 @@ public Foo() {
</example>
</rule>
<rule name="AvoidConstantsInterface"
message="An Interface should be used only to model a behaviour; consider converting this to a class."
class="net.sourceforge.pmd.rules.XPathRule">
<description>
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.
</description>
<properties>
<property name="xpath">
<value>
<![CDATA[
//ClassOrInterfaceDeclaration[@Interface="true"]
[
count(//MethodDeclaration)=0
and
count(//FieldDeclaration)>0
]
]]>
</value>
</property>
</properties>
<priority>3</priority>
<example>
<![CDATA[
public interface ConstantsInterface {
public static final int CONSTANT1=0;
public static final String CONSTANT2="1";
}
]]>
</example>
</rule>
</ruleset>

View File

@ -45,6 +45,7 @@
</subsection>
<subsection name="Contributors">
<ul>
<li>Fabio Insaccanebbia - AvoidConstantsInterface, AvoidDecimalLiteralsInBigDecimalConstructor, ClassCastExceptionWithToArray</li>
<li>David Corley - Nifty Javascript folding for XML report, <a href="http://tomcopeland.blogs.com/juniordeveloper/2005/12/demo_of_some_ni.html">demo is here</a></li>
<li>George Sexton - Bug report 1379701 for CompareObjectsWithEquals, suggested new rule for Additional String Concatenation Warnings in StringBuffer.</li>
<li>Didier Duquennoy - several bug reports for InefficientStringBuffering, bug report for ImmutableField, suggestions for improving Benchmark utility, bug report for InefficientStringBuffering, bug report for AvoidConcateningNonLiteralsInStringBuffer, reported a missed hit for EqualsNull, bug report for MissingStaticMethodInNonInstantiatableClass, pmd-netbeans feedback</li>
@ -59,7 +60,6 @@
<li><a href="http://www.jroller.com/page/Fester">Wim Deblauwe</a> - suggested UseAssertNullInsteadOfAssertTrue, bug report 1373510 for UseAssertSameInsteadOfAssertTrue, suggested putting property names/values in generated docs, UselessOverridingMethod, reported bug in JUnitTestsShouldContainAsserts, front page and "how to make a ruleset" patches, noted problems with web site rule index, bug report for JUnitTestsShouldContainAsserts, Clover license coordination and implementation, UseCorrectExceptionLogging, coordinated and coded a much nicer asXML() implementation, suggested cleanup of UnusedFormalParameter, Javadoc patch, SystemPrintln bug report, helped get Ant task and CLI squared away with JDK 1.5 params, JDK 1.5-specific bug reports, suggested improvements for ExceptionSignatureDeclaration</li>
<li>Sean Montgomery - bug report 1371980 for InefficientStringBuffering</li>
<li>Jean-Marc Vanel - suggested enhancements to the PMD scoreboard</li>
<li>Fabio Insaccanebbia - AvoidDecimalLiteralsInBigDecimalConstructor, ClassCastExceptionWithToArray</li>
<li><a href="http://www.websoup.net/">Andriy Rozeluk</a> - suggested UseStringBufferLength, bug report 1306180 for AvoidConcatenatingNonLiteralsInStringBuffer, reported bug 1293157 for UnusedPrivateMethod, suggested UnnecessaryCaseChange, bug report for SimplifyConditional, suggested UnnecessaryLocalBeforeReturn, suggestions for improving BooleanInstantiation, UnnecessaryReturn, AvoidDuplicateLiterals RFEs and bug reports, various other RFEs and thoughtful discussions as well</li>
<li>Bruno Juillet - suggested reporting suppressed warnings, bug report for missing package/class/method names, patch for Ant task's excludeMarker attribute, bug report on ruleset overrides</li>
<li>Chris Erskine - documentation suggestions</li>