com.puppycrawl.tools.checkstyle.checks

Class HeaderCheck

Implemented Interfaces:
Configurable, Contextualizable

public class HeaderCheck
extends AbstractHeaderCheck

Checks the header of the source against a fixed header file.

Rationale: In most projects each file must have a fixed header, since usually the header contains copyright information.

The header contents are specified in the file identified by property headerFile.

Property ignoreLines specifies the line numbers to ignore when matching lines in a header file. The property type is a comma-separated list of integers 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:
 line 3: // Checks Java source code for adherence to a set of rules.
 line 4: // Copyright (C) 2001  Oliver Burn
 line 5: ////////////////////////////////////////////////////////////////////
 

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

An example of how to configure the check to use header file "java.header" and ignore lines 2, 3, and 4 is:

 <module name="Header">
    <property name="headerFile" value="java.header"/>
    <property name="ignoreLines" value="2, 3, 4"/>
 </module>
 

Author:
Lars K?hne

Method Summary

void
beginTree(DetailAST aRootAST)
protected boolean
isMatch(int aLineNumber)
Checks if a code line matches the required header line.
void
setIgnoreLines(int[] aList)
Set the lines numbers to ignore in the header check.

Methods inherited from class com.puppycrawl.tools.checkstyle.checks.AbstractHeaderCheck

finishLocalSetup, getDefaultTokens, getHeaderLines, setHeader, setHeaderFile

Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check

beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getDefaultTokens, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens, visitToken

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, log, log, setSeverity

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

configure, contextualize, finishLocalSetup, getConfiguration, setupChild

Method Details

beginTree

public void beginTree(DetailAST aRootAST)
Overrides:
beginTree in interface Check


isMatch

protected boolean isMatch(int aLineNumber)
Checks if a code line matches the required header line.

Parameters:
aLineNumber - the linenumber to check against the header

Returns:
true if and only if the line matches the required header line


setIgnoreLines

public void setIgnoreLines(int[] aList)
Set the lines numbers to ignore in the header check.

Parameters:
aList - comma separated list of line numbers to ignore in header.