checkstyle配置文件中英文对照

1 <?xml version="1.0" encoding="GBK"?>
2 <!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
3 "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
4 <!--
5 Checkstyle configuration that checks the sun coding conventions from:
6 - the Java Language Specification at
7 http://java.sun.com/docs/books/jls/second_edition/html/index.html
8 - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
9 - the Javadoc guidelines at
10 http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
11 - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
12 - some best practices
13 Checkstyle is very configurable. Be sure to read the documentation at
14 http://checkstyle.sf.net (or in your downloaded distribution).
15 Most Checks are configurable, be sure to consult the documentation.
16 To completely disable a check, just comment it out or delete it from the file.
17 Finally, it is worth reading the documentation.
18 -->
19 <module name="Checker">
20 <property name="severity" value="warning"/>
21
22 <!--
23 If you set the basedir property below, then all reported file
24 names will be relative to the specified directory. See
25 http://checkstyle.sourceforge.net/5.x/config.html#Checker
26 <property name="basedir" value="${basedir}"/>
27 -->
28 <!-- Checks that a package-info.java file exists for each package. -->
29 <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
30 <module name="JavadocPackage"/>
31 <!-- Checks whether files end with a new line. -->
32 <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile
33 -->
34 <!-- 检查文件是否以一个新行结束-->
35 <module name="NewlineAtEndOfFile"/>
36 <!-- Checks that property files contain the same keys. -->
37 <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
38 <!-- 检查**.properties配置文件 是否有没有设值的key-->
39 <module name="Translation"/>
40
41 <!-- Checks for Size Violations. -->
42 <!-- See http://checkstyle.sf.net/config_sizes.html -->
43 <!-- 检查文件的长度 default max=2000 -->
44 <module name="FileLength"/>
45
46 <!-- Checks for whitespace -->
47 <!-- See http://checkstyle.sf.net/config_whitespace.html -->
48 <!-- 检查文件中是否含有'\t'-->
49 <module name="FileTabCharacter"/>
50 <!-- Miscellaneous other checks. -->
51 <!-- See http://checkstyle.sf.net/config_misc.html -->
52 <!-- 不知道作用 -->
53 <module name="RegexpSingleline">
54 <property name="format" value="\s+$"/>
55 <property name="minimum" value="0"/>
56 <property name="maximum" value="0"/>
57 <property name="message" value="Line has trailing spaces."/>
58 </module>
59 <module name="TreeWalker">
60 <!-- Checks for Javadoc comments. -->
61 <!-- See http://checkstyle.sf.net/config_javadoc.html -->
62 <!-- Checks the Javadoc of a method or constructor. By default, does not check for unused throws. To allow documented java.lang.RuntimeExceptions that are not declared, set property allowUndeclaredRTE to true. The scope to verify is specified using the Scope class and defaults to Scope.PRIVATE. To verify another scope, set property scope to a different scope. -->
63 <module name="JavadocMethod">
64 <property name="logLoadErrors" value="true"/>
65 <property name="suppressLoadErrors" value="true"/>
66 </module>
67 <!-- Checks Javadoc comments for class and interface definitions. By default, does not check for author or version tags. The scope to verify is specified using the Scope class and defaults to Scope.PRIVATE. To verify another scope, set property scope to one of the Scope constants. To define the format for an author tag or a version tag, set property authorFormat or versionFormat respectively to a regular expression.-->
68 <module name="JavadocType"/>
69 <!-- Checks that variables have Javadoc comments. -->
70 <module name="JavadocVariable"/>
71 <!-- Validates Javadoc comments to help ensure they are well formed. The following checks are performed:
72 * Ensures the first sentence ends with proper punctuation (That is a period, question mark, or exclamation mark, by default). Javadoc automatically places the first sentence in the method summary table and index. With out proper punctuation the Javadoc may be malformed. All items eligible for the {@inheritDoc} tag are exempt from this requirement.
73 * Check text for Javadoc statements that do not have any description. This includes both completely empty Javadoc, and Javadoc with only tags such as @param and @return.
74 * Check text for incomplete HTML tags. Verifies that HTML tags have corresponding end tags and issues an "Unclosed HTML tag found:" error if not. An "Extra HTML tag found:" error is issued if an end tag is found without a previous open tag.
75 * Check that a package Javadoc comment is well-formed (as described above) and NOT missing from any package-info.java files.
76 * Check for allowed HTML tags. The list of allowed HTML tags is "a", "abbr", "acronym", "address", "area", "b", "bdo", "big", "blockquote", "br", "caption", "cite", "code", "colgroup", "del", "div", "dfn", "dl", "em", "fieldset", "h1" to "h6", "hr", "i", "img", "ins", "kbd", "li", "ol", "p", "pre", "q", "samp", "small", "span", "strong", "sub", "sup", "table", "tbody", "td", "tfoot", "th", "thread", "tr", "tt", "ul".
77 These checks were patterned after the checks made by the DocCheck doclet available from Sun. -->
78 <!--<module name="JavadocStyle"/>-->
79
80 <!-- Checks for Naming Conventions. -->
81 <!-- See http://checkstyle.sf.net/config_naming.html -->
82 <!-- Each of these naming modules validates identifiers for particular code elements. Valid identifiers for a naming module are specified by its format property. The value of format is a regular expression for valid identifiers. -->
83 <!-- constants (static, final fields) -->
84 <module name="ConstantName"/>
85 <!-- local, final variables, including catch parameters -->
86 <module name="LocalFinalVariableName"/>
87 <!-- local, non-final variables, including catch parameters-->
88 <module name="LocalVariableName"/>
89 <!-- non-static fields -->
90 <module name="MemberName"/>
91 <!-- methods -->
92 <module name="MethodName"/>
93 <!-- packages -->
94 <module name="PackageName"/>
95 <!-- parameters -->
96 <module name="ParameterName"/>
97 <!-- static, non-final fields -->
98 <module name="StaticVariableName"/>
99 <!-- classes and interfaces -->
100 <module name="TypeName"/>
101
102 <!-- Checks for Headers -->
103 <!-- See http://checkstyle.sf.net/config_header.html -->
104 <!-- <module name="Header"> -->
105 <!-- The follow property value demonstrates the ability -->
106 <!-- to have access to ANT properties. In this case it uses -->
107 <!-- the ${basedir} property to allow Checkstyle to be run -->
108 <!-- from any directory within a project. See property -->
109 <!-- expansion, -->
110 <!-- http://checkstyle.sf.net/config.html#properties -->
111 <!-- <property -->
112 <!-- name="headerFile" -->
113 <!-- value="${basedir}/java.header"/> -->
114 <!-- </module> -->
115 <!-- Following interprets the header file as regular expressions. -->
116 <!-- <module name="RegexpHeader"/> -->
117
118 <!-- Checks for imports -->
119 <!-- See http://checkstyle.sf.net/config_import.html -->
120 <!-- 必须导入类的完整路径,即不能使用*导入所需的类 -->
121 <module name="AvoidStarImport"/>
122 <!-- 检查是否从非法的包中导入了类 illegalPkgs: 定义非法的包名称-->
123 <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
124 <!-- 检查是否导入了不必显示导入的类-->
125 <module name="RedundantImport"/>
126 <!-- 检查是否导入的包没有使用-->
127 <module name="UnusedImports"/>
128
129 <!-- Checks for Size Violations. -->
130 <!-- See http://checkstyle.sf.net/config_sizes.html -->
131 <!-- Checks for long methods and constructors. max default 150. max=80设置长度80 -->
132 <module name="MethodLength"/>
133 <!-- Checks the number of parameters of a method or constructor. max default 7. -->
134 <module name="ParameterNumber"/>
135 <!-- Checks for long lines.
136 Rationale: Long lines are hard to read in printouts or if developers have limited screen space for the source code, e.g. if the IDE displays additional information like project tree, class hierarchy, etc. -->
137 <module name="LineLength"/>
138 <!-- Checks for whitespace -->
139 <!-- See http://checkstyle.sf.net/config_whitespace.html -->
140 <!-- 检查for iterator语句是否使用空格
141 option: 定义初始化语句是否使用空格,例如:space表示使用空格,则for(Iterator iterator = List.iterator(); iterator.hasNext(); iterator.next())就是形式合理的,否则就是形式不合理的-->
142 <module name="EmptyForIteratorPad"/>
143 <!-- 检查方法参数的格式
144 allowLineBreaks: 参数是否允许在不同行(注:没有作用)
145 option: 在参数和括号、参数和标识符之间是否包含空格-->
146 <module name="MethodParamPad"/>
147 <!-- Checks that there is no whitespace after a token. More specifically, it checks that it is not followed by whitespace, or (if linebreaks are allowed) all characters on the line after are whitespace. To forbid linebreaks after a token, set property allowLineBreaks to false. -->
148 <module name="NoWhitespaceAfter"/>
149 <!-- Checks that there is no whitespace before a token. More specifically, it checks that it is not preceded with whitespace, or (if linebreaks are allowed) all characters on the line before are whitespace. To allow linebreaks before a token, set property allowLineBreaks to true. -->
150 <module name="NoWhitespaceBefore"/>
151 <!-- 检查运算符是否在应在同一行
152 option: 定义运算符的位置,eol在同一行,nl在下一行
153 tokens: 定义检查的类型-->
154 <module name="OperatorWrap"/>
155 <!-- 检查左小括号'('后边和右小括号')'前边是否有空格
156 option: space表示有空格,nospace表示没有空格
157 tokens: 定义检查的类型-->
158 <module name="ParenPad"/>
159 <!-- Checks the policy on the padding of parentheses for typecasts. That is, whether a space is required after a left parenthesis and before a right parenthesis, or such spaces are forbidden. -->
160 <module name="TypecastParenPad"/>
161 <!-- 检查类型后是否包含空格 Checks that a token is followed by whitespace.
162 tokens: 检查的类型 -->
163 <module name="WhitespaceAfter"/>
164 <!-- Checks that a token is surrounded by whitespace. Empty constructor and method bodies (blocks) of the form
165 public MyClass() {} // empty constructor
166 public void func() {} // empty method
167 may optionally be exempted from the policy using the allowEmptyMethods and allowEmptyConstructors properties.
168 allowEmptyConstructors default value is false
169 allowEmptyMethods default value is false
170 -->
171 <module name="WhitespaceAround"/>
172
173 <!-- Modifier Checks -->
174 <!-- See http://checkstyle.sf.net/config_modifiers.html -->
175 <!-- ModifierOrder 检查修饰符的顺序,默认是 public,protected,private,abstract,static,final,transient,volatile,synchronized,native,strictfp-->
176 <module name="ModifierOrder"/>
177 <!-- 检查是否有多余的修饰符,例如:接口中的方法不必使用public、abstract修饰
178 tokens: 检查的类型 -->
179 <module name="RedundantModifier"/>
180
181 <!-- Checks for blocks. You know, those {}'s -->
182 <!-- See http://checkstyle.sf.net/config_blocks.html -->
183 <!-- 检查是否有嵌套的代码块
184 allowInSwitchCase: 定义是否允许switch case中使用嵌套的代码块 -->
185 <module name="AvoidNestedBlocks"/>
186 <!-- 检查是否有空代码块
187 option: 定义代码块中应该包含的内容,例如:stmt表示语句
188 tokens: 检查的类型-->
189 <module name="EmptyBlock"/>
190 <!--option: 定义左大括号'{'显示位置,eol在同一行显示,nl在下一行显示
191 maxLineLength: 大括号'{'所在行行最多容纳的字符数
192 tokens: 该属性适用的类型,例:CLASS_DEF,INTERFACE_DEF,METHOD_DEF,CTOR_DEF -->
193 <module name="LeftCurly"/>
194 <!-- NeedBraces 检查是否应该使用括号的地方没有加括号
195 tokens: 定义检查的类型 -->
196 <module name="NeedBraces"/>
197 <!-- Checks the placement of right curly braces ('}') for else, try, and catch tokens. The policy to verify is specified using property option.
198 option: 右大括号是否单独一行显示
199 tokens: 定义检查的类型 -->
200 <module name="RightCurly"/>
201
202 <!-- Checks for common coding problems -->
203 <!-- See http://checkstyle.sf.net/config_coding.html -->
204 <!-- 检查是否在同一行初始化, 例如:private int Age = nGe==1 ? 100 : 0; 就应该避免
205 Detects inline conditionals. An example inline conditional is this:
206 String a = getParameter("a");
207 String b = (a==null || a.length<1) ? null : a.substring(1);
208 Rationale: Some developers find inline conditionals hard to read, so their company's coding standards forbids them. -->
209 <module name="AvoidInlineConditionals"/>
210 <!-- The "double-checked locking" idiom (DCL) tries to avoid the runtime cost of synchronization. An example that uses the DCL idiom is this:
211 public class MySingleton
212 {
213 private static theInstance = null;
214 private MySingleton() {}
215 public MySingleton getInstance() {
216 if ( theInstance == null ) { // synchronize only if necessary
217 synchronized( MySingleton.class ) {
218 if ( theInstance == null ) {
219 theInstance = new MySingleton();
220 }
221 }
222 }
223 }
224 }
225 The problem with the DCL idiom in Java is that it just does not work correctly. Using it introduces bugs that are extremely hard to track down and reproduce. The "Double-Checked Locking is Broken" Declaration has an in depth explanation of the exact problem which has to do with the semantics of the Java memory model.
226 The DoubleCheckedLocking check will find source code where a test is wrapped in a synchronized block that is wrapped in the same test, like in the example above. -->
227 <module name="DoubleCheckedLocking"/> <!-- MY FAVOURITE -->
228 <!--Detects empty statements (standalone ;). -->
229 <module name="EmptyStatement"/>
230 <!-- 检查在重写了equals方法后是否重写了hashCode方法 -->
231 <module name="EqualsHashCode"/>
232 <!-- Checks that a local variable or a parameter does not shadow a field that is defined in the same class.-->
233 <module name="HiddenField"/>
234 <!-- Checks for illegal instantiations where a factory method is preferred.
235 Rationale: Depending on the project, for some classes it might be preferable to create instances through factory methods rather than calling the constructor.
236 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().
237 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. -->
238 <module name="IllegalInstantiation">
239 <property name="classes" value="java.lang.Boolean"/>
240 </module>
241 <!-- Checks for assignments in subexpressions, such as in String s = Integer.toString(i = 2);.
242 Rationale: With the exception of for iterators, all assignments should occur in their own toplevel statement to increase readability. With inner assignments like the above it is difficult to see all places where a variable is set. -->
243 <module name="InnerAssignment"/>
244 <!-- 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. -->
245 <module name="MagicNumber"/>
246 <!-- Checks that switch statement has "default" clause. 检查switch语句是否有‘default’从句
247 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. -->
248 <module name="MissingSwitchDefault"/>
249 <!-- Checks for redundant exceptions declared in throws clause such as duplicates, unchecked exceptions or subclasses of another declared exception. 检查是否抛出了多余的异常 -->
250 <module name="RedundantThrows">
251 <property name="logLoadErrors" value="true"/>
252 <property name="suppressLoadErrors" value="true"/>
253 </module>
254 <!-- Checks for overly complicated boolean expressions. Currently finds code like if (b == true), b || true, !false, etc.
255 检查boolean值是否冗余的地方
256 Rationale: Complex boolean logic makes code hard to understand and maintain. -->
257 <module name="SimplifyBooleanExpression"/>
258 <!-- Checks for overly complicated boolean return statements. For example the following code
259 检查是否存在过度复杂的boolean返回值
260 if (valid())
261 return false;
262 else
263 return true;
264 could be written as
265 return !valid();
266 The Idea for this Check has been shamelessly stolen from the equivalent PMD rule. -->
267 <module name="SimplifyBooleanReturn"/>
268 <!-- Checks for class design -->
269 <!-- See http://checkstyle.sf.net/config_design.html -->
270 <!-- Checks that classes are designed for extension. More specifically, it enforces a programming style where superclasses provide empty "hooks" that can be implemented by subclasses.
271 检查子类是否非法破坏了父类或接口的限制条件
272 The exact rule is that nonprivate, nonstatic methods of classes that can be subclassed must either be
273 * abstract or
274 * final or
275 * have an empty implementation
276 Rationale: This API design style protects superclasses against beeing broken by subclasses. The downside is that subclasses are limited in their flexibility, in particular they cannot prevent execution of code in the superclass, but that also means that subclasses cannot corrupt the state of the superclass by forgetting to call the super method. -->
277 <module name="DesignForExtension"/>
278 <!-- Checks that a class which has only private constructors is declared as final.只有私有构造器的类必须声明为final-->
279 <module name="FinalClass"/>
280 <!-- Make sure that utility classes (classes that contain only static methods or fields in their API) do not have a public constructor.
281 确保Utils类(只提供static方法和属性的类)没有public构造器。
282 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.
283 If you make the constructor protected you may want to consider the following constructor implementation technique to disallow instantiating subclasses:
284 public class StringUtils // not final to allow subclassing
285 {
286 protected StringUtils() {
287 throw new UnsupportedOperationException(); // prevents calls from subclass
288 }
289 public static int count(char c, String s) {
290 // ...
291 }
292 }-->
293 <module name="HideUtilityClassConstructor"/>
294 <!-- Implements Bloch, Effective Java, Item 17 - Use Interfaces only to define types.
295 不允许interface像java.ioSerializable一样只作为标记,不包含任何methods和constants。
296 According to Bloch, an interface should describe a type. It is therefore inappropriate to define an interface that does not contain any methods but only constants. The Standard class javax.swing.SwingConstants is an example of a class that would be flagged by this check.
297 The check can be configured to also disallow marker interfaces like java.io.Serializable, that do not contain methods or constants at all. -->
298 <module name="InterfaceIsType"/>
299 <!-- 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.
300 检查class成员属性可见性。只有static final 修饰的成员是可以public的。其他的成员属性必需是private的,除非属性protectedAllowed或者packageAllowed设置了true.
301 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.
302 Rationale: Enforce encapsulation. 强制封装 -->
303 <module name="VisibilityModifier"/>
304
305 <!-- Miscellaneous other checks. -->
306 <!-- See http://checkstyle.sf.net/config_misc.html -->
307 <!-- 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[])
308 检查再定义数组时,采用java风格还是c风格,例如:int[] num是java风格,int num[]是c风格。默认是java风格-->
309 <module name="ArrayTypeStyle"/>
310 <!-- Check that method/constructor/catch block parameters are final. Interface and abstract methods are not checked - the final keyword does not make sense for interface and abstract method parameters as there is no code that could modify the parameter.
311 检查method/constructor/catch块中的参数是否是final修饰的。
312 Rationale: Changing the value of parameters during the execution of the method's algorithm can be confusing and should be avoided. A great way to let the Java compiler prevent this coding style is to declare parameters final. -->
313 <!-- <module name="FinalParameters"/> -->
314 <!-- 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.
315 检查是否存在TODO(待处理) TODO是javaIDE自动生成的。一般代码写完后要去掉。
316 -->
317 <module name="TodoComment"/>
318 <!-- 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.
319 检查是否在long类型是否定义了大写的L.字母小写l和数字1(一)很相似。
320 looks a lot like 1. -->
321 <module name="UpperEll"/>
322 </module>
323 </module>

 

posted @ 2011-01-12 15:21  chinaifne  阅读(1944)  评论(0编辑  收藏  举报