Checks for Headers

The property checkstyle.header.file controls whether to check that each file begins with a specified header. The header contents are specified in the file. If no file is specified, checkstyle does not check for a header. The property type is string and defaults to an empty string (which means do not check).

The property checkstyle.header.ignoreline specifies the line numbers to ignore when matching lines in a header file. The property type is integer set and defaults to an empty list.

This property is very useful for supporting headers that contain copyright dates. For example, consider the following header:

line 1: ///////////////////////////////////////////////////////////////////////
line 2: // checkstyle: Checks Java source code for adherence to a set of rules.
line 3: // Copyright (C) 2001  Oliver Burn
line 4: ///////////////////////////////////////////////////////////////////////

Since the year information will change over time, you can tell checkstyle to ignore line 3 by setting the property to 3.

The property checkstyle.header.regexp controls whether to interpret each header line as a regular expression. The property type is boolean and defaults to false.

For example, consider the following header when regular expression checking is turned on:

line 1: /{71}
line 2: // checkstyle: Checks Java source code for adherence to a set of rules\.
line 3: // Copyright \(C\) \d\d\d\d  Oliver Burn
line 4: // Last modification by \$Author.*\$
line 5: /{71}

Lines 1 and 5 demonstrate a more compact notation for 71 '/' characters. Line 3 enforces that the copyright notice includes a four digit year. Line 4 is an example how to enforce revision control keywords in a file header.


Copyright © 2002 Oliver Burn. All rights Reserved.