249 lines
7.6 KiB
HTML
249 lines
7.6 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>Modifier 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>Modifier 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="#ModifierOrder">ModifierOrder</a>
|
|
</li>
|
|
<li>
|
|
<a href="#RedundantModifier">RedundantModifier</a>
|
|
</li>
|
|
<li>
|
|
<a href="#VisibilityModifier">VisibilityModifier</a>
|
|
</li>
|
|
</ul>
|
|
</td>
|
|
<!--Content-->
|
|
<td class="content" valign="top" align="left"><a name="ModifierOrder"></a> <h2>ModifierOrder</h2>
|
|
<h4>Description</h4>
|
|
|
|
<p class="body">
|
|
Checks that the order of modifiers conforms to the suggestions in the <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html">Java
|
|
Language specification, sections 8.1.1, 8.3.1 and 8.4.3</a>. The correct order
|
|
is:
|
|
</p>
|
|
|
|
<ol class="body">
|
|
<li>
|
|
<span class="code">public</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">protected</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">private</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">abstract</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">static</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">final</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">transient</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">volatile</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">synchronized</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">native</span>
|
|
</li>
|
|
<li>
|
|
<span class="code">strictfp</span>
|
|
</li>
|
|
</ol>
|
|
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="ModifierOrder"/>
|
|
</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="RedundantModifier"></a><h2>RedundantModifier</h2>
|
|
|
|
<p class="body">
|
|
Checks that method declarations in interfaces include neither the <span class="code">
|
|
public</span> modifier nor the <span class="code">abstract</span> modifier (see
|
|
the <a
|
|
href="http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html">Java
|
|
Language specification, section 9.4</a>).
|
|
</p>
|
|
<p class="body">
|
|
Also checks that variable declarations in interfaces include none of the following
|
|
modifiers: <span class="code">public</span>, <span class="code">static</span>,
|
|
<span class="code">final</span> (variables in interface definitions are constants
|
|
and have these modifiers implicitly, see the <a
|
|
href="http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html">Java
|
|
Language specification, section 9.3</a>).
|
|
</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 METHOD_DEF, VARIABLE_DEF</td>
|
|
<td>METHOD_DEF, VARIABLE_DEF</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="RedundantModifier"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to check only methods and not variables:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="RedundantModifier">
|
|
<property name="tokens" value="METHOD_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="VisibilityModifier"></a><h2>VisibilityModifier</h2>
|
|
<p class="body">
|
|
Checks visibility of class members. Only static final members
|
|
may be public; other class members must be private unless
|
|
property <span class="code">protectedAllowed</span> or <span
|
|
class="code">packageAllowed</span> is set.
|
|
</p>
|
|
|
|
<p class="body">
|
|
Public members are not flagged if the name matches the public
|
|
member regular expression (contains <span
|
|
class="code">"^serialVersionUID$"</span> by default). Note:
|
|
Checkstyle 2 used to include <span
|
|
class="code">"^f[A-Z][a-zA-Z0-9]*$"</span> in the default
|
|
pattern to allow CMP for EJB 1.1 with the default settings.
|
|
With EJB 2.0 it is not longer necessary to have public access
|
|
for persistent fields, hence the default has been changed.
|
|
</p>
|
|
<p class="body">
|
|
Rationale: Enforce encapsulation.
|
|
</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>packageAllowed</td>
|
|
<td>whether package visible members are allowed</td>
|
|
<td><a href="property_types.html#boolean">boolean</a></td>
|
|
<td><span class="default">false</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>protectedAllowed</td>
|
|
<td>whether protected members are allowed</td>
|
|
<td><a href="property_types.html#boolean">boolean</a></td>
|
|
<td><span class="default">false</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td>publicMemberPattern</td>
|
|
<td>pattern for public members that should be ignored</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td><span class="default">^serialVersionUID$</span></td>
|
|
</tr>
|
|
</table>
|
|
<h4>Examples</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="VisibilityModifier"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it allows package visible members:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="VisibilityModifier">
|
|
<property name="packageAllowed" value="true"/>
|
|
</module>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check so that it allows no public members:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="VisibilityModifier">
|
|
<property name="publicMemberPattern" value="^$"/>
|
|
</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>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<hr />
|
|
<p class="copyright">
|
|
Copyright © 2002-2003 Oliver Burn. All rights Reserved.
|
|
</p>
|
|
|
|
</body>
|
|
</html>
|