386 lines
13 KiB
HTML
386 lines
13 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 blocks</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 blocks</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="#EmptyBlock">EmptyBlock</a>
|
|
</li>
|
|
<li>
|
|
<a href="#LeftCurly">LeftCurly</a>
|
|
</li>
|
|
<li>
|
|
<a href="#NeedBraces">NeedBraces</a>
|
|
</li>
|
|
<li>
|
|
<a href="#RightCurly">RightCurly</a>
|
|
</li>
|
|
<li>
|
|
<a href="#AvoidNestedBlocks">AvoidNestedBlocks</a>
|
|
</li>
|
|
</ul>
|
|
</td>
|
|
<!--Content-->
|
|
<td class="content" valign="top" align="left"><a name="EmptyBlock"></a> <h2>EmptyBlock</h2>
|
|
<h4>Description</h4>
|
|
<p class="body">
|
|
Checks for empty blocks.
|
|
</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>option</td>
|
|
<td>policy on block contents</td>
|
|
<td><a href="property_types.html#block">block policy</a></td>
|
|
<td><span class="default">stmt</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>tokens</td>
|
|
<td>blocks to check</td>
|
|
|
|
<td>subset of tokens <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">LITERAL_CATCH</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">LITERAL_DO</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">LITERAL_ELSE</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FINALLY">LITERAL_FINALLY</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">LITERAL_IF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">LITERAL_FOR</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">LITERAL_TRY</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">LITERAL_WHILE</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_INIT">STATIC_INIT</a></td>
|
|
|
|
<td>all tokens</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="EmptyBlock"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check for the <span class="code">text</span> policy and only <span class="code">
|
|
catch</span> blocks:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="EmptyBlock">
|
|
<property name="option" value="text"/>
|
|
<property name="tokens" value="LITERAL_CATCH"/>
|
|
</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="LeftCurly"></a> <h2>LeftCurly</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for the placement of left curly braces (<span class="code">'{'</span>) for code blocks.
|
|
The policy to verify is specified using property <span class="code">option</span>.
|
|
Policies <span class="code">eol</span> and <span class="code">
|
|
nlow</span> take into account property <span class="code">maxLineLength</span>.
|
|
</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>option</td>
|
|
<td>policy on placement of a left curly brace (<span class="code">'{'</span>)</td>
|
|
<td><a href="property_types.html#lcurly">left curly brace policy</a></td>
|
|
<td><span class="default">eol</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>maxLineLength</td>
|
|
<td>maximum number of characters in a line</td>
|
|
<td><a href="property_types.html#integer">integer</a></td>
|
|
<td><span class="default">80</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>tokens</td>
|
|
<td>blocks to check</td>
|
|
|
|
<td>subset of tokens <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">CLASS_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#INTERFACE_DEF">INTERFACE_DEF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">LITERAL_CATCH</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">LITERAL_DO</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">LITERAL_ELSE</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FINALLY">LITERAL_FINALLY</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">LITERAL_FOR</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">LITERAL_IF</a>,
|
|
<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#LITERAL_SYNCHRONIZED">LITERAL_SYNCHRONIZED</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">LITERAL_TRY</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">LITERAL_WHILE</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a></td>
|
|
|
|
<td>all tokens</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="LeftCurly"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to apply the <span class="code">nl</span> policy to type blocks:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="LeftCurly">
|
|
<property name="option" value="nl"/>
|
|
<property name="tokens" value="CLASS_DEF,INTERFACE_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="NeedBraces"></a> <h2>NeedBraces</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks for braces around code blocks.
|
|
</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#LITERAL_DO">LITERAL_DO</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">LITERAL_ELSE</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">LITERAL_IF</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">LITERAL_FOR</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">LITERAL_WHILE</a></td>
|
|
|
|
<td>all tokens</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="NeedBraces"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check for <span class="code">if</span> and <span class="code">
|
|
else</span> blocks:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="NeedBraces">
|
|
<property name="tokens" value="LITERAL_IF, LITERAL_ELSE"/>
|
|
</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="RightCurly"></a> <h2>RightCurly</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks the placement of right curly braces (<span class="code">'}'</span>) for <span class="code">
|
|
else</span>, <span class="code">try</span>, and <span class="code">catch</span>
|
|
tokens. The policy to verify is specified using property <span class="code">
|
|
option</span>.
|
|
</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>option</td>
|
|
<td>policy on placement of a right curly brace (<span class="code">'}'</span>)</td>
|
|
<td><a href="property_types.html#rcurly">right curly brace policy</a></td>
|
|
<td><span class="default">same</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>tokens</td>
|
|
<td>blocks to check</td>
|
|
|
|
<td>subset of tokens <a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">LITERAL_CATCH</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">LITERAL_ELSE</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">LITERAL_TRY</a></td>
|
|
|
|
<td><a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">LITERAL_CATCH</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">LITERAL_ELSE</a>,
|
|
<a
|
|
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">LITERAL_TRY</a></td>
|
|
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="RightCurly"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check with policy <span class="code">alone</span> for <span class="code">
|
|
else</span> tokens:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="RightCurly">
|
|
<property name="option" value="alone"/>
|
|
<property name="tokens" value="LITERAL_ELSE"/>
|
|
</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="AvoidNestedBlocks"></a> <h2>AvoidNestedBlocks</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Finds nested blocks, i.e. blocks that are used freely in the code.
|
|
For example this Check finds the obsolete braces in
|
|
</p>
|
|
<pre class="body">
|
|
switch (a)
|
|
{
|
|
case 0:
|
|
{
|
|
x = 1;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
</pre>
|
|
<p class="body">
|
|
and flags confusing code like
|
|
</p>
|
|
<pre class="body">
|
|
public void guessTheOutput()
|
|
{
|
|
int whichIsWich = 0;
|
|
{
|
|
int whichIsWhich = 2;
|
|
}
|
|
System.out.println("value = " + whichIsWhich);
|
|
}
|
|
</pre>
|
|
<p class="body">
|
|
Rationale: Nested blocks are often leftovers from the debugging process, they confuse
|
|
the reader.
|
|
</p>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="AvoidNestedBlocks"/>
|
|
</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>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<hr />
|
|
<div><a href="index.html">Back to the Checkstyle Home Page</a></div>
|
|
<p class="copyright">
|
|
Copyright © 2002-2003 Oliver Burn. All rights Reserved.
|
|
</p>
|
|
|
|
</body>
|
|
</html> |