checkstyle/docs/config_naming.html

193 lines
8.3 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 Naming Conventions</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 Naming Conventions</h1></td>
<td align="right"><img src="logo.png" alt="Checkstyle Logo"/></td>
</tr>
</table>
<!-- content -->
<h2>Overview</h2>
<p class="body">
Each of these naming modules validates identifiers for particular code elements. Valid
identifiers for a naming module are specified by its <span class="code">
format</span> property. The value of <span class="code">format</span> is a <a href="http://jakarta.apache.org/regexp/">regular
expression</a> for valid identifiers.
This is an example of a configuration of the <span class="code">MemberName</span> module to
ensure that member identifiers begin with <span class="code">&#39;m&#39;</span>,
followed by an upper case letter, and then letters and digits:
</p>
<pre class="body">
&lt;module name=&quot;MemberName&quot;&gt;
&lt;property name=&quot;format&quot; value=&quot;^m[A-Z][a-zA-Z0-9]*$&quot;/&gt;
&lt;/module&gt;
</pre>
<p class="body">
All naming modules belong to package
<span class="code">com.puppycrawl.tools.checkstyle.checks.naming</span> and are submodules of
<a href="config.html#treewalker"><span class="code">TreeWalker</span></a>.
</p>
<h2>Modules</h2>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>module</th>
<th>validates identifiers for</th>
<th>default value of <span class="code">format</span></th>
</tr>
<tr>
<td><span class="code">AbstractClassName</span></td>
<td><span class="code">abstract</span> classes</td>
<td><span class="default">^Abstract.*$|^.*Factory$</span></td>
</tr>
<tr>
<td><span class="code">ConstantName</span></td>
<td>constants (<span class="code">static</span>, <span class="code">
final</span> fields)</td>
<td><span class="default">^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$</span></td>
</tr>
<tr>
<td><span class="code">LocalFinalVariableName</span></td>
<td>local, <span class="code">final</span> variables</td>
<td><span class="default">^[a-z][a-zA-Z0-9]*$</span></td>
</tr>
<tr>
<td><span class="code">LocalVariableName</span></td>
<td>local, non-<span class="code">final</span> variables, including
<span class="code">catch</span> parameters</td>
<td><span class="default">^[a-z][a-zA-Z0-9]*$</span></td>
</tr>
<tr>
<td><span class="code">MemberName</span></td>
<td>non-<span class="code">static</span> fields</td>
<td><span class="default">^[a-z][a-zA-Z0-9]*$</span></td>
</tr>
<tr>
<td><span class="code">MethodName</span></td>
<td>methods</td>
<td><span class="default">^[a-z][a-zA-Z0-9]*$</span></td>
</tr>
<tr>
<td><span class="code">PackageName</span></td>
<td>packages</td>
<td><span class="default">^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$</span></td>
</tr>
<tr>
<td><span class="code">ParameterName</span></td>
<td>parameters</td>
<td><span class="default">^[a-z][a-zA-Z0-9]*$</span></td>
</tr>
<tr>
<td><span class="code">StaticVariableName</span></td>
<td><span class="code">static</span>, non-<span class="code">final</span> fields</td>
<td><span class="default">^[a-z][a-zA-Z0-9]*$</span></td>
</tr>
<tr>
<td><span class="code">TypeName</span></td>
<td>classes and interfaces</td>
<td><span class="default">^[A-Z][a-zA-Z0-9]*$</span></td>
</tr>
</table>
<h2>Notes</h2>
<ul class="body">
<li>
The default value of <span class="code">format</span> for
module <span class="code">PackageName</span> has
been chosen to match the requirements in the <a href="http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html#40169">Java
Language specification</a> and the Sun coding conventions. However both
underscores and uppercase letters are rather uncommon, so most configurations should
probably assign value <span class="code">^[a-z]+(\.[a-z][a-z0-9]*)*$</span> to
<span class="code">format</span> for
module <span class="code">PackageName</span>, as in
<pre class="body">
&lt;module name=&quot;PackageName&quot;&gt;
&lt;property name=&quot;format&quot; value=&quot;^[a-z]+(\.[a-z][a-z0-9]*)*$&quot;/&gt;
&lt;/module&gt;
</pre>
</li>
<li>
Module <span class="code">LocalVariableName</span> also has property <span class="code">tokens</span>
which can be used to control whether the check applies to variable declarations or
<span class="code">catch</span> clause parameters through
tokens
<span class="code">VARIABLE_DEF</span> and <span class="code">PARAMETER_DEF</span>.
For example, the following configuration element ensures that
<span class="code">catch</span> clause parameters begin with <span class="code">"e"</span>,
followed by letters and digits:
<pre class="body">
&lt;module name=&quot;LocalVariableName&quot;&gt;
&lt;property name=&quot;format&quot; value=&quot;^e[a-zA-Z0-9]*$&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;PARAMETER_DEF&quot;/&gt;
&lt;/module&gt;
</pre>
</li>
<li>
Module <span class="code">TypeName</span> also has property <span class="code">tokens</span>
which can be used to control whether the check applies to classes or interfaces through
tokens
<span class="code">CLASS_DEF</span> and <span class="code">INTERFACE_DEF</span>.
For example, the following configuration element ensures that
interface names begin with <span class="code">"I_"</span>, followed by letters and digits:
<pre class="body">
&lt;module name=&quot;TypeName&quot;&gt;
&lt;property name=&quot;format&quot; value=&quot;^I_[a-zA-Z0-9]*$&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;INTERFACE_DEF&quot;/&gt;
&lt;/module&gt;
</pre>
</li>
<li>Module <span class="code">TypeName</span> also has the
following properties:
<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>applyToPublic</td>
<td>Controls whether to apply the check to public member.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">true</span></td>
</tr>
<tr>
<td>applyToProtected</td>
<td>Controls whether to apply the check to protected member.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">true</span></td>
</tr>
<tr>
<td>applyToPackage</td>
<td>Controls whether to apply the check to package-private member.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">true</span></td>
</tr>
<tr>
<td>applyToPrivate</td>
<td>Controls whether to apply the check to pribvate member.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">true</span></td>
</tr>
</table>
</li>
</ul>
<hr />
<div><a href="index.html">Back to the Checkstyle Home Page</a></div>
<p class="copyright">
Copyright &copy; 2002-2004 Oliver Burn. All rights Reserved.
</p>
</body>
</html>