forked from phoedos/pmd
New ExcessivePublicCountRule thanks to Andy Glover
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1494 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
?????? - 1.04
|
||||
Added new rules: ConstructorCallsOverridableMethodRule, AtLeastOneConstructorRule, JUnitAssertionsShouldIncludeMessageRule, DoubleCheckedLockingRule
|
||||
Added new rules: ConstructorCallsOverridableMethodRule, AtLeastOneConstructorRule, JUnitAssertionsShouldIncludeMessageRule, DoubleCheckedLockingRule, ExcessivePublicCountRule
|
||||
The Ant task has been updated; if you set "verbose=true" full stacktraces are printed. Thx to Paul Roebuck for the suggestion.
|
||||
|
||||
February 11, 2003 - 1.03
|
||||
|
@ -0,0 +1,22 @@
|
||||
package test.net.sourceforge.pmd.rules;
|
||||
|
||||
import net.sourceforge.pmd.rules.ExcessivePublicCountRule;
|
||||
|
||||
public class ExcessivePublicCountRuleTest extends RuleTst {
|
||||
|
||||
private ExcessivePublicCountRule rule;
|
||||
|
||||
public ExcessivePublicCountRuleTest() {
|
||||
rule = new ExcessivePublicCountRule();
|
||||
}
|
||||
|
||||
public void testSimpleOK() throws Throwable {
|
||||
rule.addProperty("minimum", "50");
|
||||
super.runTest("ExcessivePublicCountRule1.java", 0, rule);
|
||||
}
|
||||
|
||||
public void testSimpleBad() throws Throwable {
|
||||
rule.addProperty("minimum", "2");
|
||||
super.runTest("ExcessivePublicCountRule2.java", 1, rule);
|
||||
}
|
||||
}
|
@ -189,6 +189,38 @@ These are new rules for the next release
|
||||
|
||||
</rule>
|
||||
|
||||
<rule name="ExcessivePublicCountRule"
|
||||
message="A high number of public methods and attributes in an object can indicate the class may need to be broken up for exhaustive testing may prove difficult."
|
||||
class="net.sourceforge.pmd.rules.ExcessivePublicCountRule">
|
||||
<description>
|
||||
A large amount of public methods and attributes declared in an object can indicate the class may need
|
||||
to be broken up as increased effort will be required to thoroughly test such a class.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="45"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
|
||||
public class Foo {
|
||||
public String value;
|
||||
public Bar something;
|
||||
public Variable var;
|
||||
//more public attributes
|
||||
public void doWork() {}
|
||||
public void doMoreWork() {}
|
||||
public void doWorkAgain() {}
|
||||
public void doWorking() {}
|
||||
public void doWorkIt() {}
|
||||
public void doWorkingAgain() {}
|
||||
public void doWorkAgainAgain() {}
|
||||
public void doWorked() {}
|
||||
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
@ -0,0 +1,52 @@
|
||||
package net.sourceforge.pmd.rules;
|
||||
|
||||
import net.sourceforge.pmd.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.ast.ASTFieldDeclaration;
|
||||
import net.sourceforge.pmd.ast.ASTMethodDeclarator;
|
||||
import net.sourceforge.pmd.ast.AccessNode;
|
||||
import net.sourceforge.pmd.rules.design.ExcessiveNodeCountRule;
|
||||
|
||||
/**
|
||||
* @author aglover
|
||||
*
|
||||
* Class Name: ExcessivePublicCountRule
|
||||
*
|
||||
* Rule attempts to count all public methods and public attributes defined in a class.
|
||||
*
|
||||
* If a class has a high number of public operations, it might be wise to consider whether
|
||||
* it would be appropriate to divide it into subclasses.
|
||||
*
|
||||
* A large proportion of public members and operations means the class has high potential to be
|
||||
* affected by external classes. Futhermore, increased effort will be required to
|
||||
* thoroughly test the class.
|
||||
*/
|
||||
public class ExcessivePublicCountRule extends ExcessiveNodeCountRule {
|
||||
|
||||
public ExcessivePublicCountRule() {
|
||||
super(ASTCompilationUnit.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method counts ONLY public methods.
|
||||
*/
|
||||
public Object visit(ASTMethodDeclarator node, Object data) {
|
||||
return this.getTallyOnAccessType((AccessNode)node.jjtGetParent());
|
||||
}
|
||||
/**
|
||||
* Method counts ONLY public class attributes
|
||||
*/
|
||||
public Object visit(ASTFieldDeclaration node, Object data) {
|
||||
return this.getTallyOnAccessType(node);
|
||||
}
|
||||
/**
|
||||
* Method counts a node if it is public
|
||||
* @param AccessNode node
|
||||
* @return Integer 1 if node is public 0 otherwise
|
||||
*/
|
||||
private Integer getTallyOnAccessType(AccessNode node){
|
||||
if(node.isPublic()){
|
||||
return new Integer(1);
|
||||
}
|
||||
return new Integer(0);
|
||||
}
|
||||
}
|
3
pmd/test-data/ExcessivePublicCountRule1.java
Normal file
3
pmd/test-data/ExcessivePublicCountRule1.java
Normal file
@ -0,0 +1,3 @@
|
||||
public class ExcessivePublicCountRule1 {
|
||||
public int foo;
|
||||
}
|
6
pmd/test-data/ExcessivePublicCountRule2.java
Normal file
6
pmd/test-data/ExcessivePublicCountRule2.java
Normal file
@ -0,0 +1,6 @@
|
||||
public class ExcessivePublicCountRule2 {
|
||||
public int foo;
|
||||
public int bif;
|
||||
public int baz;
|
||||
public int bof;
|
||||
}
|
@ -10,7 +10,8 @@
|
||||
<section name="Credits">
|
||||
<subsection name="Individuals">
|
||||
<ul>
|
||||
<li>Andrew Glover - CouplingBetweenObjectsRule, ExcessiveImportsRule. documentation tweaks</li>
|
||||
<li>Andrew Glover - ExcessivePublicCountRule, CouplingBetweenObjectsRule, ExcessiveImportsRule, documentation tweaks</li>
|
||||
<li>Egon Willighagen - pmd-web suggestion</li>
|
||||
<li>Carl Gilbert - DoubleCheckedLockingRule, ConstructorCallsOverridableMethodRule, bug reports, feature requests, and documentation improvements</li>
|
||||
<li>Vladimir Bossicard - numerous feature requests and bug reports, several rule suggestions derived from <a href="http://junit-addons.sf.net/">JUnit-Addons</a>, evangelism :-)</li>
|
||||
<li>Didier Duquennoy - pmd-netbeans feedback</li>
|
||||
|
Reference in New Issue
Block a user