From 2a30b5aba207ce85e6cff7645a6d17f8dbda9521 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Fri, 1 Oct 2010 13:56:48 +1000 Subject: [PATCH] Added MethodCount that checks the number of methods declared in each type. This includes the number of each scope as well as an overall total. Thanks to Alexander Jesse for patch #1151669, which was the inspiration. --- .../checks/sizes/MethodCountCheck.java | 2 +- src/xdocs/availablechecks.xml | 4 + src/xdocs/config_sizes.xml | 83 +++++++++++++++++++ src/xdocs/releasenotes.xml | 8 ++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/sizes/MethodCountCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/sizes/MethodCountCheck.java index 24a93d5d7..76adfb142 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/sizes/MethodCountCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/sizes/MethodCountCheck.java @@ -92,7 +92,7 @@ public final class MethodCountCheck extends Check }; /** default maximum number of methods */ - private static final int DEFAULT_MAX_METHODS = 999; + private static final int DEFAULT_MAX_METHODS = 100; /** Maximum private methods. */ private int mMaxPrivate = DEFAULT_MAX_METHODS; /** Maximum package methods. */ diff --git a/src/xdocs/availablechecks.xml b/src/xdocs/availablechecks.xml index c1e8777c3..851a3187f 100644 --- a/src/xdocs/availablechecks.xml +++ b/src/xdocs/availablechecks.xml @@ -353,6 +353,10 @@ Checks that instance variable names conform to a format specified by the format property. + + MethodCount + Checks the number of methods declared in each type. + MethodLength diff --git a/src/xdocs/config_sizes.xml b/src/xdocs/config_sizes.xml index 4d6c27b84..5ece32391 100755 --- a/src/xdocs/config_sizes.xml +++ b/src/xdocs/config_sizes.xml @@ -525,5 +525,88 @@ +
+ +

+ Checks the number of methods declared in each type. This + includes the number of each scope (private, + package, protected and + public) as well as an overall total. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namedescriptiontypedefault value
maxTotalmaximum allowable number of methods at all scope levelsinteger100
maxPrivatemaximum allowable number of private methodsinteger100
maxPackagemaximum allowable number of package methodsinteger100
maxProtectedmaximum allowable number of protected methodsinteger100
maxPublicmaximum allowable number of public methodsinteger100
+
+ + +

+ To configure the check with defaults: +

+ +<module name="MethodCount"/> + + +

+ To configure the check to allow at most 30 methods per type: +

+ +<module name="MethodCount"> + <property name="maxTotal" value="30"/> +</module> + + +
+ + +

+ com.puppycrawl.tools.checkstyle.checks.sizes +

+
+ + +

+ TreeWalker +

+
+
+ diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index 0e1597492..0886643db 100755 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -31,6 +31,14 @@ depth (default = 1). Thanks to Alexander Jesse for patch #1151673. +
  • + Added MethodCount + that checks the number of methods declared in each type. This + includes the number of each scope (private, + package, protected and + public) as well as an overall total. Thanks to + Alexander Jesse for patch #1151669, which was the inspiration. +
  • Bug fixes: