888 lines
32 KiB
HTML
888 lines
32 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<title>Miscellaneous Checks</title>
|
|
<link rel="stylesheet" type="text/css" href="mystyle.css"/>
|
|
</head>
|
|
|
|
<body>
|
|
<!-- The header -->
|
|
<table border="0" width="100%" summary="header layout">
|
|
<tr>
|
|
<td><h1>Miscellaneous Checks</h1></td>
|
|
<td align="right"><img src="logo.png" alt="Checkstyle Logo"/></td>
|
|
</tr>
|
|
</table>
|
|
<!-- content -->
|
|
<table border="0" width="100%" cellpadding="5" summary="body layout">
|
|
<tr>
|
|
<!--Left menu-->
|
|
<td class="menu" valign="top">
|
|
<ul>
|
|
<li>
|
|
<a href="#ArrayTypeStyle">ArrayTypeStyle</a>
|
|
</li>
|
|
<li>
|
|
<a href="#DescendantToken">DescendantToken</a>
|
|
</li>
|
|
<li>
|
|
<a href="#FinalParameters">FinalParameters</a>
|
|
</li>
|
|
<li>
|
|
<a href="#GenericIllegalRegexp">GenericIllegalRegexp</a>
|
|
</li>
|
|
<li>
|
|
<a href="#Indentation">Indentation</a>
|
|
</li>
|
|
<li>
|
|
<a href="#NewlineAtEndOfFile">NewlineAtEndOfFile</a>
|
|
</li>
|
|
<li>
|
|
<a href="#TodoComment">TodoComment</a>
|
|
</li>
|
|
<li>
|
|
<a href="#TrailingComment">TrailingComment</a>
|
|
</li>
|
|
<li>
|
|
<a href="#Translation">Translation</a>
|
|
</li>
|
|
<li>
|
|
<a href="#UncommentedMain">UncommentedMain</a>
|
|
</li>
|
|
<li>
|
|
<a href="#UpperEll">UpperEll</a>
|
|
</li>
|
|
</ul>
|
|
</td>
|
|
<!--Content-->
|
|
<td class="content" valign="top" align="left">
|
|
|
|
<!-- --> <a name="GenericIllegalRegexp"></a> <h2>GenericIllegalRegexp</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
A generic check for code problems - the user can search for any pattern. This is
|
|
similar to a recursive grep, only that it's integrated in checkstyle.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: This check can be used to prototype checks and to find common bad
|
|
practice such as calling <span class="code">ex.printStacktrace()</span>, <span class="code">
|
|
System.out.println()</span>, <span class="code">System.exit()</span>, etc.
|
|
</p>
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>format</td>
|
|
<td>illegal pattern</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td><span class="default">^$</span> (empty)</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ignoreCase</td>
|
|
<td>Controls whether to ignore case when searching.</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><span class="default">false</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>ignoreComments</td>
|
|
<td>Controls whether to ignore text in comments when searching.</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><span class="default">false</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>message</td>
|
|
<td>message which is used to notify about violations,
|
|
if empty then default(hard-coded) message is used.</td>
|
|
<td><a href="property_types.html#String">String</a></td>
|
|
<td><span class="default">""</span>(empty)</td>
|
|
</tr>
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check for calls to <span class="code">System.out.println</span>:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="GenericIllegalRegexp">
|
|
<!-- . matches any character, so we need to
|
|
escape it and use \. to match dots. -->
|
|
<property name="format" value="System\.out\.println"/>
|
|
</module>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to find trailing whitespace at the end of a line:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="GenericIllegalRegexp">
|
|
<!-- \s matches whitespace character, $ matches end of line. -->
|
|
<property name="format" value="\s$"/>
|
|
</module>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to find case-insensitive occurrences of "debug":
|
|
</p>
|
|
<pre class="body">
|
|
<module name="GenericIllegalRegexp">
|
|
<property name="format" value="debug"/>
|
|
<property name="ignoreCase" value="true"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
<!-- --> <a name="NewlineAtEndOfFile"></a> <h2>NewlineAtEndOfFile</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks whether files end with a new line.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Any source files and text files in general should end with a newline
|
|
character, especially when using SCM systems such as CVS. CVS will even
|
|
print a warning when it encounters a file that doesn't end with a newline.
|
|
</p>
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>lineSeparator</td>
|
|
<td>type of line separator</td>
|
|
<td>One of "system" (system default), "crlf" (Windows-style), "cr" (Mac-style) and "lf" (Unix-style)</td>
|
|
<td>system default</td>
|
|
</tr>
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="NewlineAtEndOfFile"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to always use Unix-style line separators:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="NewlineAtEndOfFile">
|
|
<property name="lineSeparator" value="lf"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#checker">Checker</a>
|
|
</p>
|
|
<!-- --> <a name="TodoComment"></a> <h2>TodoComment</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
A check for <span class="code">TODO:</span> comments. Actually it is a generic <a href="http://jakarta.apache.org/regexp/apidocs/org/apache/regexp/RE.html">regular
|
|
expression</a> matcher on Java comments. To check for other patterns in Java
|
|
comments, set property format.
|
|
</p>
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>format</td>
|
|
<td>pattern to check</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td><span class="default">TODO:</span></td>
|
|
</tr>
|
|
</table>
|
|
<h4>Notes</h4>
|
|
<p class="body">
|
|
Using <span class="code">TODO:</span> comments is a great way to keep track of
|
|
tasks that need to be done. Having them reported by Checkstyle makes it very
|
|
hard to forget about them.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="TodoComment"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check for comments that contain <span class="code">WARNING</span>:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="TodoComment">
|
|
<property name="format" value="WARNING"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
<!-- --> <a name="Translation"></a> <h2>Translation</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
A <a href="config.html#overview">FileSetCheck</a> that ensures the correct
|
|
translation of code by checking property files for consistency regarding their
|
|
keys. Two property files describing one and the same context are consistent if
|
|
they contain the same keys.
|
|
</p>
|
|
<p class="body">
|
|
Consider the following properties file in the same directory:
|
|
</p>
|
|
<pre>
|
|
#messages.properties
|
|
hello=Hello
|
|
cancel=Cancel
|
|
|
|
#messages_de.properties
|
|
hell=Hallo
|
|
ok=OK
|
|
</pre>
|
|
<p class="body">
|
|
The Translation check will find the typo in the german hello key, the
|
|
missing ok key in the default resource file and the missing cancel key
|
|
in the german resource file:
|
|
</p>
|
|
<pre>
|
|
messages_de.properties: Key 'hello' missing.
|
|
messages_de.properties: Key 'cancel' missing.
|
|
messages.properties: Key 'hell' missing.
|
|
messages.properties: Key 'ok' missing.
|
|
</pre>
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>fileExtensions</td>
|
|
<td>file type extension to identify translation files. Setting this property
|
|
is typically only required if your translation files are preprocessed
|
|
and the original files do not have the extension
|
|
<span class="code">.properties</span></td>
|
|
<td><a href="property_types.html#stringSet">String Set</a></td>
|
|
<td><span class="default">properties</span></td>
|
|
</tr>
|
|
</table>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="Translation"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#checker">Checker</a>
|
|
</p>
|
|
<!-- --> <a name="UncommentedMain"></a> <h2>UncommentedMain</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for uncommented main() methods (debugging leftovers).
|
|
</p>
|
|
<p class="body"> Rationale: A main() method is often used for
|
|
debug puposes. When debugging is finished, developers often forget
|
|
to remove the method, which changes the API and increases the size
|
|
of the resulting class/jar file. With the exception of the real
|
|
program entry points, all main() methods should be removed/commented
|
|
out of the sources.
|
|
</p>
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>excludedClasses</td>
|
|
<td>pattern for qualified names of classes which are allowed
|
|
to have a main method.</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td><span class="default">^$</span></td>
|
|
</tr>
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="UncommentedMain"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to allow main method for all classes with
|
|
"Main" name:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="UncommentedMain">
|
|
<property name="excludedClasses" value="\.Main$"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks
|
|
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
|
|
</p>
|
|
|
|
<!-- --> <a name="UpperEll"></a> <h2>UpperEll</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that long constants are defined with an upper ell. That is <span class="code">'
|
|
L'</span> and
|
|
not <span class="code">'l'</span>. This is in accordance to the Java Language
|
|
Specification, <a href="http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#48282">
|
|
Section
|
|
3.10.1</a>.
|
|
</p>
|
|
<p class="body"> Rationale: The letter <span class="code">l</span> looks a lot
|
|
like <span class="code">1</span>.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
|
|
</p>
|
|
<pre class="body">
|
|
<module name="UpperEll"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks
|
|
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
|
|
</p>
|
|
|
|
<!-- --> <a name="ArrayTypeStyle"></a> <h2>ArrayTypeStyle</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks the style of array type definitions.
|
|
Some like Java-style: <code>public static void main(String[] args)</code>
|
|
and some like C-style: public static void main(String args[])
|
|
</p>
|
|
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>javaStyle</td>
|
|
<td>Controls whether to enforce Java style (true) or C style (false).</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><span class="default">true</span></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check to enforce Java style:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="ArrayTypeStyle"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to enforce C style:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="ArrayTypeStyle">
|
|
<property name="javaStyle" value="false"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="FinalParameters"></a> <h2>FinalParameters</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Check that method/constructor/catch block parameters are final. Interface methods are not checked -
|
|
the final keyword does not make sense for interface method parameters as there is no code
|
|
that could modify the parameter.
|
|
</p>
|
|
<p class="body">
|
|
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.
|
|
</p>
|
|
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>tokens</td>
|
|
<td>blocks to check</td>
|
|
|
|
<td>subset of tokens <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">LITERAL_CATCH</a></td>
|
|
|
|
<td><a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a></td>
|
|
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check to enforce final parameters for methods and constructors:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="FinalParameters"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to enforce final parameters only for constructors:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="FinalParameters">
|
|
<property name="tokens" value="CTOR_DEF"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="DescendantToken"></a> <h2>DescendantToken</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for restricted tokens beneath other tokens.
|
|
</p>
|
|
<p class="body">
|
|
WARNING: This is a very powerful and flexible check, but, at the
|
|
same time, it is low level and very implementation dependent
|
|
because its results depend on the grammar we use to build abstract
|
|
syntax trees. Thus we recomend using other checks when
|
|
they provide the desired funcionality. All in all, this check just
|
|
works on the level of an abstract tree and knows nothing about language
|
|
structures.
|
|
</p>
|
|
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>tokens</td>
|
|
<td>token types to check</td>
|
|
<td>subset of tokens declared in <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a></td>
|
|
<td>empty set</td>
|
|
</tr>
|
|
<tr>
|
|
<td>limitedTokens</td>
|
|
<td>set of tokens with limited occurances as descendants</td>
|
|
<td>subset of tokens declared in <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a></td>
|
|
<td>empty set</td>
|
|
<tr>
|
|
<td>minimumDepth</td>
|
|
<td>the mimimum depth for descendant counts</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td>0</td>
|
|
</tr>
|
|
<tr>
|
|
<td>maximumDepth</td>
|
|
<td>the maximum depth for descendant counts</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td>java.lang.Integer.MAX_VALUE</td>
|
|
</tr>
|
|
<tr>
|
|
<td>minimumNumber</td>
|
|
<td>a minimum count for descendants</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td>0</td>
|
|
</tr>
|
|
<tr>
|
|
<td>maximumNumber</td>
|
|
<td>a maximum count for descendants</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td>java.lang.Integer.MAX_VALUE</td>
|
|
</tr>
|
|
<tr>
|
|
<td>minimumMessage</td>
|
|
<td>error message when minimum count not reached</td>
|
|
<td><a href="property_types.html#String">String</a></td>
|
|
<td>"descendant.token.min"</td>
|
|
</tr>
|
|
<tr>
|
|
<td>maximumMessage</td>
|
|
<td>error message when maximum count exceeded</td>
|
|
<td><a href="property_types.html#String">String</a></td>
|
|
<td>"descendant.token.max"</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<pre>
|
|
String literal equality check:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="EQUAL,NOT_EQUAL"/>
|
|
<property name="limitedTokens" value="STRING_LITERAL"/>
|
|
<property name="maximumNumber" value="0"/>
|
|
<property name="maximumDepth" value="1"/>
|
|
</module>
|
|
|
|
Switch with no default:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="LITERAL_SWITCH"/>
|
|
<property name="maximumDepth" value="2"/>
|
|
<property name="limitedTokens" value="LITERAL_DEFAULT"/>
|
|
<property name="minimumNumber" value="1"/>
|
|
</module>
|
|
|
|
Assert statement may have side effects (formatted for browser display):
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="LITERAL_ASSERT"/>
|
|
<property name="limitedTokens" value="ASSIGN,DEC,INC,POST_DEC,
|
|
POST_INC,PLUS_ASSIGN,MINUS_ASSIGN,STAR_ASSIGN,DIV_ASSIGN,MOD_ASSIGN,
|
|
BSR_ASSIGN,SR_ASSIGN,SL_ASSIGN,BAND_ASSIGN,BXOR_ASSIGN,BOR_ASSIGN,
|
|
METHOD_CALL"/>
|
|
<property name="maximumNumber" value="0"/>
|
|
</module>
|
|
|
|
Initialiser in for performs no setup (use while instead?):
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="FOR_INIT"/>
|
|
<property name="limitedTokens" value="EXPR"/>
|
|
<property name="minimumNumber" value="1"/>
|
|
</module>
|
|
|
|
Condition in for performs no check:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="FOR_CONDITION"/>
|
|
<property name="limitedTokens" value="EXPR"/>
|
|
<property name="minimumNumber" value="1"/>
|
|
</module>
|
|
|
|
Switch within switch:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="LITERAL_SWITCH"/>
|
|
<property name="limitedTokens" value="LITERAL_SWITCH"/>
|
|
<property name="maximumNumber" value="0"/>
|
|
<property name="minimumDepth" value="1"/>
|
|
</module>
|
|
|
|
Return from within a catch or finally block:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="LITERAL_FINALLY,LITERAL_CATCH"/>
|
|
<property name="limitedTokens" value="LITERAL_RETURN"/>
|
|
<property name="maximumNumber" value="0"/>
|
|
</module>
|
|
|
|
Try within catch or finally block:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="LITERAL_CATCH,LITERAL_FINALLY"/>
|
|
<property name="limitedTokens" value="LITERAL_TRY"/>
|
|
<property name="maximumNumber" value="0"/>
|
|
</module>
|
|
|
|
Too many cases within a switch:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="LITERAL_SWITCH"/>
|
|
<property name="limitedTokens" value="LITERAL_CASE"/>
|
|
<property name="maximumDepth" value="2"/>
|
|
<property name="maximumNumber" value="10"/>
|
|
</module>
|
|
|
|
Too many local variables within a method:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="METHOD_DEF"/>
|
|
<property name="limitedTokens" value="VARIABLE_DEF"/>
|
|
<property name="maximumDepth" value="2"/>
|
|
<property name="maximumNumber" value="10"/>
|
|
</module>
|
|
|
|
Too many returns from within a method:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="METHOD_DEF"/>
|
|
<property name="limitedTokens" value="LITERAL_RETURN"/>
|
|
<property name="maximumNumber" value="3"/>
|
|
</module>
|
|
|
|
Too many fields within an interface:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="INTERFACE_DEF"/>
|
|
<property name="limitedTokens" value="VARIABLE_DEF"/>
|
|
<property name="maximumDepth" value="2"/>
|
|
<property name="maximumNumber" value="0"/>
|
|
</module>
|
|
|
|
Limit the number of exceptions a method can throw:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="LITERAL_THROWS"/>
|
|
<property name="limitedTokens" value="IDENT"/>
|
|
<property name="maximumNumber" value="1"/>
|
|
</module>
|
|
|
|
Limit the number of expressions in a method:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="METHOD_DEF"/>
|
|
<property name="limitedTokens" value="EXPR"/>
|
|
<property name="maximumNumber" value="200"/>
|
|
</module>
|
|
|
|
Disallow empty statements:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="EMPTY_STAT"/>
|
|
<property name="limitedTokens" value="EMPTY_STAT"/>
|
|
<property name="maximumNumber" value="0"/>
|
|
<property name="maximumDepth" value="0"/>
|
|
<property name="maximumMessage"
|
|
value="Empty statement is not allowed."/>
|
|
</module>
|
|
|
|
Too many fields within a class:
|
|
<module name="DescendantToken">
|
|
<property name="tokens" value="CLASS_DEF"/>
|
|
<property name="limitedTokens" value="VARIABLE_DEF"/>
|
|
<property name="maximumDepth" value="2"/>
|
|
<property name="maximumNumber" value="10"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="Indentation">Indentation</a>
|
|
<h2>Indentation</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks correct indentation of Java Code.
|
|
</p>
|
|
<p class="body">
|
|
The basic idea behind this is that while
|
|
pretty printers are sometimes convienent for bulk reformats of
|
|
legacy code, they often either aren't configurable enough or
|
|
just can't anticipate how format should be done. Sometimes this is
|
|
personal preference, other times it is practical experience. In any
|
|
case, this check should just ensure that a minimal set of indentation
|
|
rules are followed.
|
|
</p>
|
|
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>basicOffset</td>
|
|
<td>how many spaces to use for new indentation level</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td>4</td>
|
|
</tr>
|
|
<tr>
|
|
<td>braceAdjustment</td>
|
|
<td>how far brace should be indented when on next line</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td>0</td>
|
|
</tr>
|
|
<tr>
|
|
<td>caseIndent</td>
|
|
<td>how much to indent a case label</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td>4</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
<pre class="body">
|
|
<module name="Indentation"/>
|
|
</pre>
|
|
</p>
|
|
<p class="body">
|
|
To configure the check to enforce indentation style recommended
|
|
by Sun:
|
|
<pre class="body">
|
|
<module name="Indentation">
|
|
<property name="caseIndent" value="0"/>
|
|
</module>
|
|
</pre>
|
|
</p>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.indentation
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="TrailingComment">TrailingComment</a>
|
|
<h2>TrailingComment</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
The check to ensure that requires that comments be the only thing on a line.
|
|
For the case of // comments that means that the only thing that should
|
|
precede it is whitespace.
|
|
It doesn't check comments if they do not end line, i.e. it accept
|
|
the following:
|
|
<code>Thread.sleep( 10 <some comment here> );</code>
|
|
Format property is intended to deal with the "} // while" example.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Steve McConnel in "Code Complete" suggests that endline
|
|
comments are a bad practice. An end line comment would
|
|
be one that is on the same line as actual code. For example:
|
|
<pre>
|
|
a = b + c; // Some insightful comment
|
|
d = e / f; // Another comment for this line
|
|
</pre>
|
|
Quoting "Code Complete" for the justfication:
|
|
<ul>
|
|
<li>
|
|
"The comments have to be aligned so that they do not
|
|
interfere with the visual structure of the code. If you don't
|
|
align them neatly, they'll make your listing look like it's been
|
|
through a washing machine."
|
|
</li>
|
|
<li>
|
|
"Endline comments tend to be hard to format...It takes time
|
|
to align them. Such time is not spent learning more about
|
|
the code; it's dedicated solely to the tedious task of
|
|
pressing the spacebar or tab key."
|
|
</li>
|
|
<li>
|
|
"Endline comments are also hard to maintain. If the code on
|
|
any line containing an endline comment grows, it bumps the
|
|
comment farther out, and all the other endline comments will
|
|
have to bumped out to match. Styles that are hard to
|
|
maintain aren't maintained...."
|
|
</li>
|
|
<li>
|
|
"Endline comments also tend to be cryptic. The right side of
|
|
the line doesn't offer much room and the desire to keep the
|
|
comment on one line means the comment must be short.
|
|
Work then goes into making the line as short as possible
|
|
instead of as clear as possible. The comment usually ends
|
|
up as cryptic as possible...."
|
|
</li>
|
|
<li>
|
|
"A systemic problem with endline comments is that it's hard
|
|
to write a meaningful comment for one line of code. Most
|
|
endline comments just repeat the line of code, which hurts
|
|
more than it helps."
|
|
</li>
|
|
</ul>
|
|
His comments on being hard to maintain when the size of
|
|
the line changes are even more important in the age of
|
|
automated refactorings.
|
|
</p>
|
|
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>format</td>
|
|
<td>pattern for string allowed before comment.</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td><span class="default">^[\\s\\}\\);]*$</span></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
<pre class="body">
|
|
<module name="TrailingComment"/>
|
|
</pre>
|
|
</p>
|
|
<p class="body">
|
|
To configure the check so it enforces only comment on a line:
|
|
<pre class="body">
|
|
<module name="TrailingComment">
|
|
<property name="format" value="^\\s*$"/>
|
|
</module>
|
|
</pre>
|
|
</p>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.indentation
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<hr />
|
|
<div><a href="index.html">Back to the Checkstyle Home Page</a></div>
|
|
<p class="copyright">
|
|
Copyright © 2002-2004 Oliver Burn. All rights Reserved.
|
|
</p>
|
|
|
|
</body>
|
|
</html>
|