Added documentation for the enhanced DescendantTokenCheck.

This commit is contained in:
Oliver Burn 2008-11-05 00:48:09 +00:00
parent 6a5d1ff834
commit 4542d7c95e
4 changed files with 92 additions and 17 deletions

View File

@ -21,5 +21,6 @@ public class InputReturnFromFinallyCheck {
public void thisNull() {
boolean result = (this == null) || (null == this);
boolean result2 = (this != null) && (null != this);
boolean result3 = (this.getClass().getName() == String.valueOf(null == System.getProperty("abc")));
}
}

View File

@ -263,6 +263,7 @@ public class DescendantTokenCheckTest extends BaseCheckTestSupport
checkConfig.addAttribute("tokens", "NOT_EQUAL,EQUAL");
checkConfig.addAttribute("limitedTokens", "LITERAL_THIS,LITERAL_NULL");
checkConfig.addAttribute("maximumNumber", "1");
checkConfig.addAttribute("maximumDepth", "1");
checkConfig.addAttribute("maximumMessage", "this cannot be null.");
checkConfig.addAttribute("sumTokenCounts", "true");
@ -285,6 +286,7 @@ public class DescendantTokenCheckTest extends BaseCheckTestSupport
checkConfig.addAttribute("tokens", "NOT_EQUAL,EQUAL");
checkConfig.addAttribute("limitedTokens", "LITERAL_THIS,LITERAL_NULL");
checkConfig.addAttribute("maximumNumber", "1");
checkConfig.addAttribute("maximumDepth", "1");
checkConfig.addAttribute("sumTokenCounts", "true");
String[] expected = {

View File

@ -645,6 +645,15 @@ messages.properties: Key 'ok' missing.
<td><a href="property_types.html#integer">Integer</a></td>
<td>java.lang.Integer.MAX_VALUE</td>
</tr>
<tr>
<td>sumTokenCounts</td>
<td>
whether the number of tokens found should be calculated
from the sum of the individual token counts
</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">false</span></td>
</tr>
<tr>
<td>minimumMessage</td>
<td>error message when minimum count not reached</td>
@ -661,24 +670,46 @@ messages.properties: Key 'ok' missing.
</subsection>
<subsection name="Examples">
<p>
Comparing <span class="code">this</span> with <span
class="code">null</span> (i.e. <span class="code">this ==
null</span> and <span class="code">this != null</span>):
</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="EQUAL,NOT_EQUAL"/&gt;
&lt;property name="limitedTokens" value="LITERAL_THIS,LITERAL_NULL"/&gt;
&lt;property name="maximumNumber" value="1"/&gt;
&lt;property name="maximumDepth" value="1"/&gt;
&lt;property name="sumTokenCounts" value="true"/&gt;
&lt;/module&gt;
</source>
<p>String literal equality check:</p>
<source>
String literal equality check:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="EQUAL,NOT_EQUAL"/&gt;
&lt;property name="limitedTokens" value="STRING_LITERAL"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;property name="maximumDepth" value="1"/&gt;
&lt;/module&gt;
</source>
Switch with no default:
<p>Switch with no default:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_SWITCH"/&gt;
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="limitedTokens" value="LITERAL_DEFAULT"/&gt;
&lt;property name="minimumNumber" value="1"/&gt;
&lt;/module&gt;
</source>
Assert statement may have side effects (formatted for browser display):
<p>
Assert statement may have side effects (formatted for browser
display):
</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_ASSERT"/&gt;
&lt;property name="limitedTokens" value="ASSIGN,DEC,INC,POST_DEC,
@ -687,89 +718,119 @@ Assert statement may have side effects (formatted for browser display):
METHOD_CALL"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;/module&gt;
</source>
Initialiser in for performs no setup (use while instead?):
<p>
Initialiser in for performs no setup (use while instead?):
</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="FOR_INIT"/&gt;
&lt;property name="limitedTokens" value="EXPR"/&gt;
&lt;property name="minimumNumber" value="1"/&gt;
&lt;/module&gt;
</source>
Condition in for performs no check:
<p>
Condition in for performs no check:
</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="FOR_CONDITION"/&gt;
&lt;property name="limitedTokens" value="EXPR"/&gt;
&lt;property name="minimumNumber" value="1"/&gt;
&lt;/module&gt;
</source>
Switch within switch:
<p>
Switch within switch:
</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_SWITCH"/&gt;
&lt;property name="limitedTokens" value="LITERAL_SWITCH"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;property name="minimumDepth" value="1"/&gt;
&lt;/module&gt;
</source>
Return from within a catch or finally block:
<p>Return from within a catch or finally block:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_FINALLY,LITERAL_CATCH"/&gt;
&lt;property name="limitedTokens" value="LITERAL_RETURN"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;/module&gt;
</source>
Try within catch or finally block:
<p>Try within catch or finally block:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_CATCH,LITERAL_FINALLY"/&gt;
&lt;property name="limitedTokens" value="LITERAL_TRY"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;/module&gt;
</source>
Too many cases within a switch:
<p>Too many cases within a switch:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_SWITCH"/&gt;
&lt;property name="limitedTokens" value="LITERAL_CASE"/&gt;
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="maximumNumber" value="10"/&gt;
&lt;/module&gt;
</source>
Too many local variables within a method:
<p>Too many local variables within a method:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="METHOD_DEF"/&gt;
&lt;property name="limitedTokens" value="VARIABLE_DEF"/&gt;
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="maximumNumber" value="10"/&gt;
&lt;/module&gt;
</source>
Too many returns from within a method:
<p>Too many returns from within a method:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="METHOD_DEF"/&gt;
&lt;property name="limitedTokens" value="LITERAL_RETURN"/&gt;
&lt;property name="maximumNumber" value="3"/&gt;
&lt;/module&gt;
</source>
Too many fields within an interface:
<p>Too many fields within an interface:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="INTERFACE_DEF"/&gt;
&lt;property name="limitedTokens" value="VARIABLE_DEF"/&gt;
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;/module&gt;
</source>
Limit the number of exceptions a method can throw:
<p>Limit the number of exceptions a method can throw:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_THROWS"/&gt;
&lt;property name="limitedTokens" value="IDENT"/&gt;
&lt;property name="maximumNumber" value="1"/&gt;
&lt;/module&gt;
</source>
Limit the number of expressions in a method:
<p>Limit the number of expressions in a method:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="METHOD_DEF"/&gt;
&lt;property name="limitedTokens" value="EXPR"/&gt;
&lt;property name="maximumNumber" value="200"/&gt;
&lt;/module&gt;
</source>
Disallow empty statements:
<p>Disallow empty statements:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="EMPTY_STAT"/&gt;
&lt;property name="limitedTokens" value="EMPTY_STAT"/&gt;
@ -778,8 +839,10 @@ Disallow empty statements:
&lt;property name="maximumMessage"
value="Empty statement is not allowed."/&gt;
&lt;/module&gt;
</source>
Too many fields within a class:
<p>Too many fields within a class:</p>
<source>
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="CLASS_DEF"/&gt;
&lt;property name="limitedTokens" value="VARIABLE_DEF"/&gt;

View File

@ -18,6 +18,12 @@
for enforcing the maximum number of outer types per file. Inspired
by patch #1145023 from Alexander Jesse.
</li>
<li>
Added the option <i>sumTokenCounts</i> to the <a
href="config_misc.html#DescendantToken">DescendantToken</a> to
allow for even more powerful checks. For example, detect
statements like <span class="code">this == null</span>.
</li>
<li>
Add new options to the <a
href="config_sizes.html#ImportOrderCheck">ImportOrderCheck</a>
@ -42,7 +48,10 @@
<p>Notes:</p>
<ul>
<li>...</li>
<li>
Please report any problems, as this may be the last beta
release.
</li>
</ul>
</section>