checkstyle/docs/config_blocks.html

317 lines
9.7 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 LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
LITERAL_IF, LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, STATIC_INIT</td>
<td>all tokens</td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;EmptyBlock&quot;/&gt;
</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">
&lt;module name=&quot;EmptyBlock&quot;&gt;
&lt;property name=&quot;option&quot; value=&quot;text&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;LITERAL_CATCH&quot;/&gt;
&lt;/module&gt;
</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 CLASS_DEF, CTOR_DEF, INTERFACE_DEF, LITERAL_CATCH, LITERAL_DO,
LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_SWITCH,
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF</td>
<td>all tokens</td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;LeftCurly&quot;/&gt;
</pre>
<p class="body">
To configure the check to apply the <span class="code">nl</span> policy to type blocks:
</p>
<pre class="body">
&lt;module name=&quot;LeftCurly&quot;&gt;
&lt;property name=&quot;option&quot; value=&quot;nl&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;CLASS_DEF,INTERFACE_DEF&quot;/&gt;
&lt;/module&gt;
</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 LITERAL_DO, LITERAL_ELSE, LITERAL_IF, LITERAL_FOR,
LITERAL_WHILE</td>
<td>all tokens</td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;NeedBraces&quot;/&gt;
</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">
&lt;module name=&quot;NeedBraces&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;LITERAL_IF, LITERAL_ELSE&quot;/&gt;
&lt;/module&gt;
</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 LITERAL_CATCH, LITERAL_ELSE, LITERAL_TRY</td>
<td>LITERAL_CATCH, LITERAL_ELSE, LITERAL_TRY</td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;RightCurly&quot;/&gt;
</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">
&lt;module name=&quot;RightCurly&quot;&gt;
&lt;property name=&quot;option&quot; value=&quot;alone&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;LITERAL_ELSE&quot;/&gt;
&lt;/module&gt;
</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">
&lt;module name=&quot;AvoidNestedBlocks&quot;/&gt;
</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 />
<p>
Copyright &copy; 2002 Oliver Burn. All rights Reserved.
</p>
</body>
</html>