CheckStyle中的MethodCount

MethodCount
检测类方法中的个数。

This check can be configured to flag classes that define too many methods to prevent the class from getting too complex. Counting can be customized to prevent too many total methods in a type definition (maxTotal), or to prevent too many methods of a specific access modifier (private, package, protected or public). Each count is completely separated to customize how many methods of each you want to allow. For example, specifying a maxTotal of 10, still means you can prevent more than 0 maxPackage methods. A violation won’t appear for 8 public methods, but one will appear if there is also 3 private methods or any package-private methods.

Methods defined in anonymous classes are not counted towards any totals. Counts only go towards the main type declaration parent, and are kept separate from it’s children’s inner types.


maxTotal maximum allowable number of methods at all scope levels default:100
maxPrivate maximum allowable number of private methods default:100
maxPackage maximum allowable number of package methods default:100
maxProtected maximum allowable number of protected methods default:100
maxPublic maximum allowable number of public methods default:100
tokens tokens to check


Example:
<module name="MethodCount">
    <property name="maxPublic" value="10"/>
    <property name="maxTotal" value="30"/>
</module>

猜你喜欢

转载自blog.csdn.net/YMilton/article/details/78666582
今日推荐