<!-- Checks the placement of right curly braces ('}') for else, try, and catch tokens. The policy to verify is specified using property option. option: 右大括号是否单独一行显示 tokens: 定义检查的类型 --> <modulename="RightCurly"> <propertyname="option"value="alone"/> </module>
<!-- Checks for illegal instantiations where a factory method is preferred. Rationale: Depending on the project, for some classes it might be preferable to create instances through factory methods rather than calling the constructor. A simple example is the java.lang.Boolean class. In order to save memory and CPU cycles, it is preferable to use the predefined constants TRUE and FALSE. Constructor invocations should be replaced by calls to Boolean.valueOf(). Some extremely performance sensitive projects may require the use of factory methods for other classes as well, to enforce the usage of number caches or object pools. --> <modulename="IllegalInstantiation"> <propertyname="classes"value="java.lang.Boolean"/> </module>
<!-- Checks for Naming Conventions. 命名规范 --> <!-- local, final variables, including catch parameters --> <modulename="LocalFinalVariableName"/>
<!-- local, non-final variables, including catch parameters--> <modulename="LocalVariableName"/>
<!-- Checks for redundant exceptions declared in throws clause such as duplicates, unchecked exceptions or subclasses of another declared exception. 检查是否抛出了多余的异常 <module name="RedundantThrows"> <property name="logLoadErrors" value="true"/> <property name="suppressLoadErrors" value="true"/> </module> -->
<!-- Checks for overly complicated boolean expressions. Currently finds code like if (b == true), b || true, !false, etc. 检查boolean值是否冗余的地方 Rationale: Complex boolean logic makes code hard to understand and maintain. --> <modulename="SimplifyBooleanExpression"/>
<!-- Checks for overly complicated boolean return statements. For example the following code 检查是否存在过度复杂的boolean返回值 if (valid()) return false; else return true; could be written as return !valid(); The Idea for this Check has been shamelessly stolen from the equivalent PMD rule. --> <modulename="SimplifyBooleanReturn"/>
<!-- Checks that a class which has only private constructors is declared as final.只有私有构造器的类必须声明为final--> <modulename="FinalClass"/>
<!-- Make sure that utility classes (classes that contain only static methods or fields in their API) do not have a public constructor. 确保Utils类(只提供static方法和属性的类)没有public构造器。 Rationale: Instantiating utility classes does not make sense. Hence the constructors should either be private or (if you want to allow subclassing) protected. A common mistake is forgetting to hide the default constructor. If you make the constructor protected you may want to consider the following constructor implementation technique to disallow instantiating subclasses: public class StringUtils // not final to allow subclassing { protected StringUtils() { throw new UnsupportedOperationException(); // prevents calls from subclass } public static int count(char c, String s) { // ... } } <module name="HideUtilityClassConstructor"/> -->
<!-- Checks visibility of class members. Only static final members may be public; other class members must be private unless property protectedAllowed or packageAllowed is set. 检查class成员属性可见性。只有static final 修饰的成员是可以public的。其他的成员属性必需是private的,除非属性protectedAllowed或者packageAllowed设置了true. Public members are not flagged if the name matches the public member regular expression (contains "^serialVersionUID$" by default). Note: Checkstyle 2 used to include "^f[A-Z][a-zA-Z0-9]*$" in the default pattern to allow CMP for EJB 1.1 with the default settings. With EJB 2.0 it is not longer necessary to have public access for persistent fields, hence the default has been changed. Rationale: Enforce encapsulation. 强制封装 --> <modulename="VisibilityModifier"/>
<!-- Checks the style of array type definitions. Some like Java-style: public static void main(String[] args) and some like C-style: public static void main(String args[]) 检查再定义数组时,采用java风格还是c风格,例如:int[] num是java风格,int num[]是c风格。默认是java风格--> <modulename="ArrayTypeStyle"> </module>
<!-- Checks that there are no "magic numbers", where a magic number is a numeric literal that is not defined as a constant. By default, -1, 0, 1, and 2 are not considered to be magic numbers. <module name="MagicNumber"> </module> -->
<!-- A check for TODO: comments. Actually it is a generic regular expression matcher on Java comments. To check for other patterns in Java comments, set property format. 检查是否存在TODO(待处理) TODO是javaIDE自动生成的。一般代码写完后要去掉。 --> <modulename="TodoComment"/>
<!-- Checks that long constants are defined with an upper ell. That is ' L' and not 'l'. This is in accordance to the Java Language Specification, Section 3.10.1. 检查是否在long类型是否定义了大写的L.字母小写l和数字1(一)很相似。 looks a lot like 1. --> <modulename="UpperEll"/>
<!-- Checks that switch statement has "default" clause. 检查switch语句是否有‘default’从句 Rationale: It's usually a good idea to introduce a default case in every switch statement. Even if the developer is sure that all currently possible cases are covered, this should be expressed in the default branch, e.g. by using an assertion. This way the code is protected aginst later changes, e.g. introduction of new types in an enumeration type. --> <modulename="MissingSwitchDefault"/>
<!-- Checks the number of parameters of a method or constructor. max default 7个. --> <modulename="ParameterNumber"> <propertyname="max"value="5"/> </module>
<!-- Checks for long methods and constructors. max default 150行. max=300 设置长度300 --> <modulename="MethodLength"> <propertyname="max"value="300"/> </module>