1717 lines
57 KiB
HTML
1717 lines
57 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>Checks for Coding problems</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>Checks for Coding problems</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="#ArrayTrailingComma">ArrayTrailingComma</a>
|
|
</li>
|
|
<li>
|
|
<a href="#AvoidInlineConditionals">AvoidInlineConditionals</a>
|
|
</li>
|
|
<li>
|
|
<a href="#CovariantEquals">CovariantEquals</a>
|
|
</li>
|
|
<li>
|
|
<a href="#DeclarationOrder">DeclarationOrder</a>
|
|
</li>
|
|
<li>
|
|
<a href="#DefaultComesLast">DefaultComesLast</a>
|
|
</li>
|
|
<li>
|
|
<a href="#DoubleCheckedLocking">DoubleCheckedLocking</a>
|
|
</li>
|
|
<li>
|
|
<a href="#EmptyStatement">EmptyStatement</a>
|
|
</li>
|
|
<li>
|
|
<a href="#EqualsHashCode">EqualsHashCode</a>
|
|
</li>
|
|
<li>
|
|
<a href="#ExplicitInitialization">ExplicitInitialization</a>
|
|
</li>
|
|
<li>
|
|
<a href="#FallThrough">FallThrough</a>
|
|
</li>
|
|
<li>
|
|
<a href="#FinalLocalVariable">FinalLocalVariable</a>
|
|
</li>
|
|
<li>
|
|
<a href="#HiddenField">HiddenField</a>
|
|
</li>
|
|
<li>
|
|
<a href="#IllegalCatch">IllegalCatch</a>
|
|
</li>
|
|
<li>
|
|
<a href="#IllegalInstantiation">IllegalInstantiation</a>
|
|
</li>
|
|
<li>
|
|
<a href="#IllegalToken">IllegalToken</a>
|
|
</li>
|
|
<li>
|
|
<a href="#IllegalTokenText">IllegalTokenText</a>
|
|
</li>
|
|
<li>
|
|
<a href="#IllegalType">IllegalType</a>
|
|
</li>
|
|
<li>
|
|
<a href="#InnerAssignment">InnerAssignment</a>
|
|
</li>
|
|
<li>
|
|
<a href="#JUnitTestCase">JUnitTestCase</a>
|
|
</li>
|
|
<li>
|
|
<a href="#MagicNumber">MagicNumber</a>
|
|
</li>
|
|
<li>
|
|
<a href="#MissingCtor">MissingCtor</a>
|
|
</li>
|
|
<li>
|
|
<a href="#MissingSwitchDefault">MissingSwitchDefault</a>
|
|
</li>
|
|
<li>
|
|
<a href="#ModifiedControlVariable">ModifiedControlVariable</a>
|
|
</li>
|
|
<li>
|
|
<a href="#MultipleStringLiterals">MultipleStringLiterals</a>
|
|
</li>
|
|
<li>
|
|
<a href="#MultipleVariableDeclarations">MultipleVariableDeclarations</a>
|
|
</li>
|
|
<li>
|
|
<a href="#NestedIfDepth">NestedIfDepth</a>
|
|
</li>
|
|
<li>
|
|
<a href="#NestedTryDepth">NestedTryDepth</a>
|
|
</li>
|
|
<li>
|
|
<a href="#PackageDeclaration">PackageDeclaration</a>
|
|
</li>
|
|
<li>
|
|
<a href="#ParameterAssignment">ParameterAssignment</a>
|
|
</li>
|
|
<li>
|
|
<a href="#RedundantThrows">RedundantThrows</a>
|
|
</li>
|
|
<li>
|
|
<a href="#ReturnCount">ReturnCount</a>
|
|
</li>
|
|
<li>
|
|
<a href="#RequireThis">RequireThis</a>
|
|
</li>
|
|
<li>
|
|
<a href="#SimplifyBooleanExpression">SimplifyBooleanExpression</a>
|
|
</li>
|
|
<li>
|
|
<a href="#SimplifyBooleanReturn">SimplifyBooleanReturn</a>
|
|
</li>
|
|
<li>
|
|
<a href="#StringLiteralEquality">StringLiteralEquality</a>
|
|
</li>
|
|
<li>
|
|
<a href="#SuperClone">SuperClone</a>
|
|
</li>
|
|
<li>
|
|
<a href="#SuperFinalize">SuperFinalize</a>
|
|
</li>
|
|
<li>
|
|
<a href="#UnnecessaryParentheses">UnnecessaryParentheses</a>
|
|
</li>
|
|
</ul>
|
|
</td>
|
|
<!--Content-->
|
|
<td class="content" valign="top" align="left">
|
|
|
|
<!-- --> <a name="ArrayTrailingComma"></a> <h2>ArrayTrailingComma</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that array initialization contains a trailing comma.
|
|
</p>
|
|
<pre class="body" >
|
|
int[] a = new int[]
|
|
{
|
|
1,
|
|
2,
|
|
3,
|
|
};
|
|
</pre>
|
|
<p class="body">
|
|
The check allows to not add a comma if both left and right curlys
|
|
are on the same line.
|
|
</p>
|
|
<pre class="body">
|
|
return new int[] { 0 };
|
|
</pre>
|
|
<p class="body">
|
|
Rationale: Putting this comma in makes it easier to change the
|
|
order of the elements or add new elements on the end.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="ArrayTrailingComma"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="AvoidInlineConditionals"></a> <h2>AvoidInlineConditionals</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Detects inline conditionals.
|
|
|
|
An example inline conditional is this:
|
|
</p>
|
|
<pre class="body" >
|
|
String a = getParameter("a");
|
|
String b = (a==null || a.length<1) ? null : a.substring(1);
|
|
</pre>
|
|
<p class="body">
|
|
Rationale: Some developers find inline conditionals hard to read,
|
|
so their company's coding standards forbids them.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="AvoidInlineConditionals"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
|
|
<!-- --> <a name="CovariantEquals"></a> <h2>CovariantEquals</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Checks that classes that define a covariant <span class="code">equals()</span>
|
|
method also override method <span class="code">equals(java.lang.Object)</span>.
|
|
Inspired by <a href="http://www.cs.umd.edu/~pugh/java/bugs/docs/findbugsPaper.pdf">findbugs</a>.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Mistakenly defining a covariant <span class="code">equals()</span>
|
|
method without overriding method <span class="code">equals(java.lang.Object)</span>
|
|
can produce unexpected runtime behaviour.
|
|
</p>
|
|
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="CovariantEquals"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="DoubleCheckedLocking"></a> <h2>DoubleCheckedLocking</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
The "double-checked locking" idiom (DCL) tries to avoid the runtime cost
|
|
of synchronization. An example that uses the DCL idiom is this:
|
|
</p>
|
|
<pre class="body">
|
|
public class MySingleton
|
|
{
|
|
private static theInstance = null;
|
|
|
|
private MySingleton() {}
|
|
|
|
public MySingleton getInstance() {
|
|
if ( theInstance == null ) { // synchronize only if necessary
|
|
synchronized( MySingleton.class ) {
|
|
if ( theInstance == null ) {
|
|
theInstance = new MySingleton();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</pre>
|
|
<p class="body">
|
|
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 <a href="http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html">
|
|
"Double-Checked Locking is Broken" Declaration</a> has an in depth explanation
|
|
of the exact problem which has to do with the semantics of the Java memory model.
|
|
</p>
|
|
<p class="body">
|
|
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.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="DoubleCheckedLocking"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="EmptyStatement"></a> <h2>EmptyStatement</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Detects empty statements (standalone ;).
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="EmptyStatement"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="EqualsHashCode"></a> <h2>EqualsHashCode</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Checks that classes that override <span class="code">equals()</span> also
|
|
override <span class="code">hashCode()</span>.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: The contract of <span class="code">equals()</span> and <span class="code">
|
|
hashCode()</span> requires that equal objects have the same hashCode. Hence,
|
|
whenever you override <span class="code">equals()</span> you must override <span class="code">
|
|
hashCode()</span> to ensure that your class can be used in collections that are
|
|
hash based.
|
|
</p>
|
|
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="EqualsHashCode"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="FinalLocalVariable"></a> <h2>FinalLocalVariable</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that local variables that never have their values changed
|
|
are declared final. The check can be configured to also check that
|
|
unchanged parameters are declared 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>tokens to check</td>
|
|
<td>subset of tokens <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a></td>
|
|
<td>
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a></td>
|
|
</tr>
|
|
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="FinalLocalVariable"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it checks local variables and parameters:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="FinalLocalVariable">
|
|
<property name="tokens" value="VARIABLE_DEF"/>
|
|
<property name="tokens" value="PARAMETER_DEF"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="HiddenField"></a> <h2>HiddenField</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that a local variable or a parameter does not shadow a field that is
|
|
defined in the same class.
|
|
</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>tokens to check</td>
|
|
<td>subset of tokens <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a></td>
|
|
|
|
<td><a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>ignoreFormat</td>
|
|
<td>pattern for names to ignore</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td>(not applied)</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>ignoreConstructorParameter</td>
|
|
<td>Controls whether to ignore constructor parameters.</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><span class="default">false</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>ignoreSetter</td>
|
|
<td>Controls whether to ignore the parameter of a property setter method, where
|
|
the property setter method for field "xyz" has name "setXyz",
|
|
one parameter named "xyz", and return type <span class="code">void</span>.</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><span class="default">false</span></td>
|
|
</tr>
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="HiddenField"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it checks local variables but not parameters:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="HiddenField">
|
|
<property name="tokens" value="VARIABLE_DEF"/>
|
|
</module>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it ignores the name "rcsid":
|
|
</p>
|
|
<pre class="body">
|
|
<module name="HiddenField">
|
|
<property name="ignoreFormat" value="^rcsid$"/>
|
|
</module>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it ignores constructor parameters:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="HiddenField">
|
|
<property name="ignoreConstructorParameter" value="true"/>
|
|
</module>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it ignores the parameter of setter methods:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="HiddenField">
|
|
<property name="ignoreSetter" value="true"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="IllegalInstantiation"></a> <h2>IllegalInstantiation</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for illegal instantiations where a factory method is preferred.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Depending on the project, for some classes it might be preferable to
|
|
create instances through factory methods rather than calling the constructor.
|
|
</p>
|
|
<p class="body">
|
|
A simple example is the <span class="code">java.lang.Boolean</span> class. In
|
|
order to save memory and CPU cycles, it is preferable to use the predefined
|
|
constants <span class="code">
|
|
TRUE</span> and <span class="code">FALSE</span>. Constructor invocations should
|
|
be replaced by calls to <span class="code">Boolean.valueOf()</span>.
|
|
</p>
|
|
<p class="body">
|
|
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.
|
|
</p>
|
|
<h4>Notes</h4>
|
|
<p class="body">
|
|
There is a limitation that it is currently not possible to specify array classes.
|
|
</p>
|
|
<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>classes</td>
|
|
<td>classes that should not be instantiated</td>
|
|
<td><a href="property_types.html#stringSet">String Set</a></td>
|
|
<td>{}</td>
|
|
</tr>
|
|
</table>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check to find instantiations of java.lang.Boolean:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="IllegalInstantiation">
|
|
<property name="classes" value="java.lang.Boolean"/>
|
|
</module>
|
|
</pre>
|
|
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="IllegalToken"></a> <h2>IllegalToken</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for illegal tokens.
|
|
</p>
|
|
<p class="body">
|
|
Rational: Certain language features often lead to hard to
|
|
maintain code or are non-obvious to novice developers. Other
|
|
features may be discouraged in certain frameworks, such as not
|
|
having native methods in EJB components.
|
|
</p>
|
|
<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>tokens to check</td>
|
|
<td>subset of <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a>,
|
|
<a</td>
|
|
<td><a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SWITCH">LITERAL_SWITCH</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#POST_INC">POST_INC</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#POST_DEC">POST_DEC</a></td>
|
|
</tr>
|
|
</table>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check to find token LITERAL_NATIVE:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="IllegalToken">
|
|
<property name="tokens" value="LITERAL_NATIVE"/>
|
|
</module>
|
|
</pre>
|
|
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
|
|
<!-- --> <a name="IllegalTokenText"></a> <h2>IllegalTokenText</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for illegal token text.
|
|
</p>
|
|
<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>tokens to check</td>
|
|
<td>subset of <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a>
|
|
</td>
|
|
<td>empty</td>
|
|
</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 matching.</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 the default 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 to forbid String literals containing <span class="code">"a href"</span>:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="IllegalTokenText">
|
|
<property name="tokens" value="STRING_LITERAL"/>
|
|
<property name="format" value="a href"/>
|
|
</module>
|
|
</pre>
|
|
|
|
<p class="body">
|
|
To configure the check to forbid leading zeros in an integer literal, other than
|
|
zero and a hex literal:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="IllegalTokenText">
|
|
<property name="tokens" value="NUM_INT,NUM_LONG"/>
|
|
<property name="format" value="^0[^lx]"/>
|
|
<property name="ignoreCase" value="true"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="InnerAssignment"></a> <h2>InnerAssignment</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for assignments in subexpressions, such as in <span class="code">String s
|
|
= Integer.toString(i = 2);</span>.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: With the exception of <span class="code">for</span> 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.
|
|
</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>assignments to check</td>
|
|
<td>subset of tokens <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ASSIGN">ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BAND_ASSIGN">BAND_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BOR_ASSIGN">BOR_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BSR_ASSIGN">BSR_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BXOR_ASSIGN">BXOR_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#DIV_ASSIGN">DIV_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#MINUS_ASSIGN">MINUS_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#MOD_ASSIGN">MOD_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PLUS_ASSIGN">PLUS_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#SL_ASSIGN">SL_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#SR_ASSIGN">SR_ASSIGN</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STAR_ASSIGN">STAR_ASSIGN</a></td>
|
|
<td>all tokens</td>
|
|
</tr>
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="InnerAssignment"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check for only <span class="code">=</span>, <span class="code">
|
|
+=</span>, and <span class="code">-=</span> operators:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="InnerAssignment">
|
|
<property name="tokens" value="ASSIGN,PLUS_ASSIGN,MINUS_ASSIGN"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="MagicNumber"></a> <h2>MagicNumber</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
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.
|
|
</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>tokens to check</td>
|
|
<td>subset of tokens NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG</td>
|
|
<td>all tokens</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ignoreNumbers</td>
|
|
<td>non-magic numbers</td>
|
|
<td>list of numbers</td>
|
|
<td>-1, 0, 1, 2</td>
|
|
</tr>
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="MagicNumber"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it checks floating-point
|
|
numbers that are neither 0, 0.5, nor 1:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="MagicNumber">
|
|
<property name="tokens" value="NUM_DOUBLE, NUM_FLOAT"/>
|
|
<property name="ignoreNumbers" value="0, 0.5, 1"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="MissingSwitchDefault"></a> <h2>MissingSwitchDefault</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that switch statement has "default" clause.
|
|
</p>
|
|
<p class="body">
|
|
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.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="MissingSwitchDefault"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="ModifiedControlVariable"></a> <h2>ModifiedControlVariable</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Check for ensuring that for loop control variables are not modified inside the for
|
|
block. An example is:
|
|
</p>
|
|
<pre class="body" >
|
|
for (int i = 0; i < 1; i++) {
|
|
i++;
|
|
}
|
|
</pre>
|
|
<p class="body">
|
|
Rationale: If the control variable is modified inside the loop body, the program
|
|
flow becomes more difficult to follow. An option is to replace the for loop
|
|
with a while loop.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="ModifiedControlVariable"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
|
|
<!-- --> <a name="RedundantThrows"></a> <h2>RedundantThrows</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for redundant exceptions declared in throws clause
|
|
such as duplicates, unchecked exceptions or subclasses of
|
|
another declared exception.
|
|
</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>allowUnchecked</td>
|
|
<td>whether unchecked exceptions in throws are allowed or not</td>
|
|
<td><a href="property_types.html#boolean">boolean</a></td>
|
|
<td><span class="default">false</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>allowSubclasses</td>
|
|
<td> whether subclass of another declared exception
|
|
is allowed in throws clause </td>
|
|
<td><a href="property_types.html#boolean">boolean</a></td>
|
|
<td><span class="default">false</span></td>
|
|
</tr>
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the default check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="RedundantThrows"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to allow unchecked exception in throws clause
|
|
</p>
|
|
<pre class="body">
|
|
<module name="RedundantThrows">
|
|
<property name="allowUnchecked" value="true"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Note</h4>
|
|
|
|
<p class="body">The classpath should be configured to locate the class
|
|
information. The classpath configuration is dependent on the
|
|
mechanism used to invoke Checkstyle.</p>
|
|
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="SimplifyBooleanExpression"></a> <h2>SimplifyBooleanExpression</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Checks for overly complicated boolean expressions. Currently finds code like <span class="code">
|
|
if (b == true)</span>, <span class="code">b || true</span>, <span class="code">!false</span>, etc.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Complex boolean logic makes code hard to understand and maintain.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="SimplifyBooleanExpression"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="SimplifyBooleanReturn"></a> <h2>SimplifyBooleanReturn</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for overly complicated boolean return statements. For example the following code
|
|
</p>
|
|
<pre class="body">
|
|
if (valid())
|
|
return false;
|
|
else
|
|
return true;
|
|
</pre>
|
|
<p class="body">
|
|
could be written as
|
|
</p>
|
|
<pre class="body">
|
|
return !valid();
|
|
</pre>
|
|
<p class="body">
|
|
The Idea for this Check has been shamelessly stolen
|
|
from the equivalent <a href="http://pmd.sourceforge.net">PMD</a> rule.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="SimplifyBooleanReturn"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="StringLiteralEquality"></a> <h2>StringLiteralEquality</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Checks that string literals are not used with
|
|
<code>==</code> or <code>!=</code>.
|
|
</p>
|
|
|
|
<p class="body">
|
|
Rationale: Novice Java programmers often use code like
|
|
<code>if (x == "something")</code> when they mean
|
|
<code>if ("something".equals(x))</code>.
|
|
</p>
|
|
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="StringLiteralEquality"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="NestedIfDepth"></a> <h2>NestedIfDepth</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Restricts nested if-else blocks to a specified depth (default = 1).
|
|
</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>max</td>
|
|
<td>allowed nesting depth</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><span class="default">1</span></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="NestedIfDepth"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to allow nesting depth 3:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="NestedIfDepth">
|
|
<property name="max" value="3"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="NestedTryDepth"></a> <h2>NestedTryDepth</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Restricts nested try blocks to a specified depth (default = 1).
|
|
</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>max</td>
|
|
<td>allowed nesting depth</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><span class="default">1</span></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="NestedTryDepth"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to allow nesting depth 3:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="NestedTryDepth">
|
|
<property name="max" value="3"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
|
|
<!-- --> <a name="SuperClone"></a> <h2>SuperClone</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that an overriding <span class="code">clone()</span> method invokes <span class="code">super.clone()</span>.
|
|
</p>
|
|
<p class="body">
|
|
Reference: <a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Object.html#clone()">Object.clone()</a>.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="SuperClone"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
|
|
<!-- --> <a name="SuperFinalize"></a> <h2>SuperFinalize</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that an overriding <span class="code">finalize()</span> method invokes <span class="code">super.finalize()</span>.
|
|
</p>
|
|
<p class="body">
|
|
Reference: <a href="http://java.sun.com/docs/books/tutorial/java/data/garbagecollection.html">Cleaning
|
|
Up Unused Objects</a>.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="SuperFinalize"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="IllegalCatch"></a> <h2>IllegalCatch</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Catching java.lang.Exception, java.lang.Error or java.lang.RuntimeException
|
|
is almost never acceptable.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Junior developers often simply catch Exception in an
|
|
attempt to handle multiple exception classes. This unfortunately
|
|
leads to code that inadvertantly catchs NPE, OutOfMemoryErrors,
|
|
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>illegalClassNames</td>
|
|
<td>exception class names to reject</td>
|
|
<td><a href="property_types.html#stringSet">list of strings</a></td>
|
|
<td><span class="default">"java.lang.Exception,
|
|
java.lang.Throwable, java.lang.RuntimeException"</span></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="IllegalCatch"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="PackageDeclaration"></a> <h2>PackageDeclaration</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Ensure a class is has a package declaration.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Classes that live in the null package cannot be
|
|
imported. Many novice developers are not aware of this.
|
|
</p>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="PackageDeclaration"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="JUnitTestCase"></a> <h2>JUnitTestCase</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Ensures that the setUp(), tearDown()methods are named correctly,
|
|
have no arguments, return void and are either public or protected.<br>
|
|
Also ensures that suite() is named correctly, have no arguments, return
|
|
junit.framewotk.Test, public and static.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: often times developers will misname one or more of these
|
|
methods and not realise that the method is not being called.
|
|
</p>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="JUnitTestCase"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="ReturnCount"></a> <h2>ReturnCount</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Restricts the number of return statements. Default = 2.
|
|
Ignores specified methods (<span class="code">equals()</span> by default).
|
|
</p>
|
|
|
|
<p class="body">
|
|
Rationale:
|
|
Too many return points can be indication that code is
|
|
attempting to do too much or may be difficult to understand.
|
|
</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>max</td>
|
|
<td>maximum allowed number of return statments</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><span class="default">2</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>format</td>
|
|
<td>method names to ingone</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td><span class="default">^equals$</span> (empty)</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check so that it doesn't allow more than three
|
|
return statements per method (<span class="code">equals()</span>
|
|
method ignored):
|
|
</p>
|
|
<pre class="body">
|
|
<module name="ReturnCount">
|
|
<property name="max" value="3"/>
|
|
</module>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it doesn't allow more than three
|
|
return statements per method for all methods:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="ReturnCount">
|
|
<property name="max" value="3"/>
|
|
<property name="format" value="^$"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="IllegalType"></a> <h2>IllegalType</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that particular class are never used as types in variable
|
|
declarations, return values or parameters. Includes
|
|
a pattern check that by default disallows abstract classes.
|
|
</p>
|
|
|
|
<p class="body">
|
|
Rationale:
|
|
Helps reduce coupling on concrete classes. In addition abstract
|
|
classes should be thought of a convenience base class implementations
|
|
of interfaces and as such are not types themsleves.
|
|
</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>tokens to check</td>
|
|
<td>subset of tokens <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>
|
|
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a></td>
|
|
|
|
<td><a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">PARAMETER_DEF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>
|
|
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td>illegalClassNames</td>
|
|
<td>classes that should not be used as types in variable
|
|
declarations, return values or parameters. </td>
|
|
<td><a href="property_types.html#stringSet">String Set</a></td>
|
|
<td>"java.util.GregorianCalendar, java.util.Hashtable,
|
|
java.util.HashSet, java.util.HashMap, java.util.ArrayList,
|
|
java.util.LinkedList, java.util.LinkedHashMap,
|
|
java.util.LinkedHashSet, java.util.TreeSet,
|
|
java.util.TreeMap, java.util.Vector"</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ignoredMethodNames</td>
|
|
<td>methods that should not be checked</td>
|
|
<td><a href="property_types.html#stringSet">String Set</a></td>
|
|
<td>"getInitialContext, getEnvironment" </td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check so that it ignore getInstance() method:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="IllegalType">
|
|
<property name="ignoredMethodNames" value="getInstance"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="DeclarationOrder"></a> <h2>DeclarationOrder</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
According to
|
|
<a
|
|
href="http://java.sun.com/docs/codeconv/html/CodeConventions.doc2.html#1852">
|
|
Code Conventions for the Java Programming Language</a>
|
|
, the parts of a class or interface declaration should appear in the
|
|
following order
|
|
|
|
<li> Class (static) variables. First the public class variables, then
|
|
the protected, then package level (no access modifier), and then
|
|
the private. </li>
|
|
<li> Instance variables. First the public class variables, then
|
|
the protected, then package level (no access modifier), and then
|
|
the private. </li>
|
|
<li> Constructors </li>
|
|
<li> Methods </li>
|
|
</p>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="DeclarationOrder"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="ParameterAssignment"></a> <h2>ParameterAssignment</h2> <h4>Description</h4>
|
|
<p class="body"> Disallow assignment of parameters.</p>
|
|
<p class="body">Rationale: Parameter assignment is often
|
|
considered poor programming practice. Forcing developers to
|
|
declare parameters as final is often onerous. Having a check
|
|
ensure that parameters are never assigned would give the best of
|
|
both worlds.</p>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="ParameterAssignment"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="ExplicitInitialization"></a> <h2>ExplicitInitialization</h2> <h4>Description</h4>
|
|
<p class="body">Checks if any class or object member explicitly
|
|
initialized to default for its type value (<span
|
|
class="code">null</span> for object references, zero for numeric
|
|
types and <span class="code">char</span> and <span
|
|
class="code">false</span> for <span
|
|
class="code">boolean</span>.</p>
|
|
<p class="body">Rationale: each instance variable gets
|
|
initialized twice, to the same value. Java
|
|
initializes each instance variable to its default
|
|
value (0 or null) before performing any
|
|
initialization specified in the code. So in this case,
|
|
x gets initialized to 0 twice, and bar gets initialized
|
|
to null twice. So there is a minor inefficiency. This style of
|
|
coding is a hold-over from C/C++ style coding,
|
|
and it shows that the developer isn't really confident that
|
|
Java really initializes instance variables to default
|
|
values.</p>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="ExplicitInitialization"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="DefaultComesLast"></a> <h2>DefaultComesLast</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Check that the <span class="code">default</span> is after all the
|
|
<span class="code">case</span>s in a <span class="code">switch</span>
|
|
statement.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Java allows <span class="code">default</span> anywhere
|
|
within the <span class="code">switch</span> statement. But it is more
|
|
readable if it comes after the last <span class="code">case</span>.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="DefaultComesLast"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="MissingCtor"></a> <h2>MissingCtor</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that classes (except abtract one) define a ctor and don't
|
|
rely on the default one.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="MissingCtor"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="FallThrough"></a> <h2>FallThrough</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for fall through in <span class="code">switch</span> statements
|
|
Finds locations where a <span class="code">case</span> contains<br>
|
|
Java code - but lacks a <span class="code">break</span>, <span
|
|
class="code">return</span>, <span class="code">throw</span> or
|
|
<span class="code">continue</span> statement.
|
|
</p>
|
|
<p class="body">
|
|
Note: the check works in assumption that there is no unreachable
|
|
code in the <span class="code">case</span>.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="FallThrough"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="MultipleStringLiterals"></a>
|
|
<h2>MultipleStringLiterals</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for multiple occurrences of the same string literal within a
|
|
single file.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Code duplication makes maintenance more difficult, so it
|
|
can be better to replace the multiple occurrences with a constant.
|
|
</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>allowedDuplicates</td>
|
|
<td>The maximum number of occurences to allow without generating a warning</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td>1</td>
|
|
</tr>
|
|
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="MultipleStringLiterals"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it allows two occurrences of each string:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="MultipleStringLiterals">
|
|
<property name="allowedDuplicates" value="2"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="MultipleVariableDeclarations"></a>
|
|
<h2>MultipleVariableDeclarations</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that each variable declaration is in its own statement
|
|
and on its own line.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: <a
|
|
href="http://java.sun.com/docs/codeconv/html/CodeConventions.doc5.html#2991">
|
|
the SUN Code conventions chapter 6.1</a> recommends that
|
|
declarations should be one per line/statement.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="MultipleVariableDeclarations"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="RequireThis"></a> <h2>RequireThis</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that code doesn't rely on the "this." default,
|
|
i.e. references to instance variables and methods of the present
|
|
object are explicitly of the form "this.varName" or
|
|
"this.methodName(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>checkFields</td>
|
|
<td>whether we should check fields usage or not</td>
|
|
<td><a href="property_types.html#boolean">boolean</a></td>
|
|
<td><span class="default">true</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>checkMethods</td>
|
|
<td>whether we should check methods usage or not</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 default check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="RequireThis"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure to check <code>this</code> qualifier for fields only:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="RequireThis">
|
|
<property name="checkMethods" value="false"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --> <a name="UnnecessaryParentheses"></a>
|
|
<h2>UnnecessaryParentheses</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for the use of unnecessary parentheses.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="UnnecessaryParentheses"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.coding
|
|
</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>
|