checkstyle/docs/config_header.html

198 lines
6.8 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 Headers</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 Headers</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="#Header">Header</a>
</li>
<li>
<a href="#RegexpHeader">RegexpHeader</a>
</li>
</ul>
</td>
<!--Content-->
<td class="content" valign="top" align="left">
<a name="Header"></a> <h2>Header</h2> <h4>Description</h4>
<p class="body">
Checks that a source file begins with a specified header. Property <span class="code">
headerFile</span> specifies a file that contains the required header.
</p>
<p class="body">
Property <span class="code">ignoreLines</span> specifies the line numbers to
ignore when matching lines in a header file. This property is very useful for
supporting headers that contain copyright dates. For example, consider the
following header:
</p>
<pre class="body">
line 1: ////////////////////////////////////////////////////////////////////
line 2: // checkstyle:
line 3: // Checks Java source code for adherence to a set of rules.
line 4: // Copyright (C) 2002 Oliver Burn
line 5: ////////////////////////////////////////////////////////////////////
</pre>
<p class="body">
Since the year information will change over time, you can tell Checkstyle to
ignore line 4 by setting property <span class="code">ignoreLines</span> to <span class="code">
4</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>headerFile</td>
<td>name of the file containing the required header</td>
<td><a href="property_types.html#string">string</a></td>
<td><span class="default">null</span></td>
</tr>
<tr>
<td>ignoreLines</td>
<td>line numbers to ignore</td>
<td><a href="property_types.html#intSet">list of integers</a></td>
<td><span class="default">{}</span></td>
</tr>
</table>
<h4>Example</h4>
<p class="body">
To configure the check to use header file <span class="code">&quot;java.header&quot;</span>
and ignore lines <span class="code">2</span>, <span class="code">3</span>, and <span class="code">
4</span>:
</p>
<pre class="body">
&lt;module name=&quot;Header&quot;&gt;
&lt;property name=&quot;headerFile&quot; value=&quot;java.header&quot;/&gt;
&lt;property name=&quot;ignoreLines&quot; value=&quot;2, 3, 4&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="RegexpHeader"></a> <h2>RegexpHeader</h2> <h4>Description</h4>
<p class="body">
Checks the header of a source file against a header file that contains a <a href="http://jakarta.apache.org/regexp/apidocs/org/apache/regexp/RE.html">regular
expression</a> for each line of the source header.
</p>
<p class="body">
Rationale: In some projects <a href="#Header">checking against a fixed header</a>
is not sufficient, e.g. the header might require a copyright line where the year
information is not static.
</p>
<p class="body">
For example, consider the following header file:
</p>
<pre class="body">
line 1: ^/{71}$
line 2: ^// checkstyle:$
line 3: ^// Checks Java source code for adherence to a set of rules\.$
line 4: ^// Copyright \(C\) \d\d\d\d Oliver Burn$
line 5: ^// Last modification by \$Author.*\$$
line 6: ^/{71}$
line 7:
line 8: ^package
line 9:
line 10: ^import
line 11:
line 12: ^/\*\*
line 13: ^ \*([^/]|$)
line 14: ^ \*/
</pre>
<p class="body">
Lines 1 and 6 demonstrate a more compact notation for 71 '/'
characters. Line 4 enforces that the copyright notice includes a
four digit year. Line 5 is an example how to enforce revision
control keywords in a file header. Lines 12-14 is a template for
javadoc (line 13 is so complecated to remove conflict with
and of javadoc comment).
</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>headerFile</td>
<td>name of the file containing the required header</td>
<td><a href="property_types.html#string">string</a></td>
<td><span class="default">null</span></td>
</tr>
<tr>
<td>multiLines</td>
<td>line numbers to repeat (zero or more times)</td>
<td><a href="property_types.html#intSet">list of integers</a></td>
<td><span class="default">{}</span></td>
</tr>
</table>
<h4>Example</h4>
<p class="body">
To configure the check to use header file <span
class="code">&quot;java.header&quot;</span> and <span
class="code">10</span> and <span class="code">13</span>
muli-lines:
</p>
<pre class="body">
&lt;module name=&quot;RegexpHeader&quot;&gt;
&lt;property name=&quot;headerFile&quot; value=&quot;java.header&quot;/&gt;
&lt;property name=&quot;multiLines&quot; value=&quot;10, 13&quot;/&gt;
&lt;/module&gt;
</pre>
<p class="body">
<u>Note</u>: <span class="code">ignoreLines</span> property has been
removed from this check to simplify it. To make some line
optional use &quot;^.*$&quot; regexp for this line.
</p>
<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 &copy; 2002-2004 Oliver Burn. All rights Reserved.
</p>
</body>
</html>