com.puppycrawl.tools.checkstyle.checks

Class RegexpHeaderCheck

Implemented Interfaces:
Configurable, Contextualizable

public class RegexpHeaderCheck
extends AbstractHeaderCheck

Checks the header of the source against a header file that contains a regular expression for each line of the source header.

Rationale: In some projects checking against a fixed header is not sufficient (see HeaderCheck), e.g. the header might require a copyright line where the year information is not static.

For example, consider the following header file:

 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}$
 

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. All lines start from ^ (line start symbol) and end with $ (line end) to force matching regexp with complete line in the source file.

An example of how to configure the check to use header file "java.header" is:

 <module name="RegexpHeader">
    <property name="headerFile" value="java.header"/>
 </module>
 

To configure the check to use header file "java.header" and 10 and 13 muli-lines:

 <module name="RegexpHeader">
   <property name="headerFile" value="java.header"/>
   <property name="multiLines" value="10, 13"/>
</module>
     

Note: ignoreLines property was removed you should use ^.*$ regexp for line to ignore it.

Authors:
Lars K?hne
o_sukhodolsky

Method Summary

void
beginTree(DetailAST aRootAST)
void
setHeader(String aHeader)
Set the header to check against.
void
setHeaderFile(String aFileName)
Sets the file that contains the header to check against.
void
setMultiLines(int[] aList)
Set the lines numbers to repeat 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


setHeader

public void setHeader(String aHeader)
Set the header to check against. Individual lines in the header must be separated by '\n' characters.
Overrides:
setHeader in interface AbstractHeaderCheck

Parameters:
aHeader - header content to check against.


setHeaderFile

public void setHeaderFile(String aFileName)
            throws ConversionException
Sets the file that contains the header to check against.
Overrides:
setHeaderFile in interface AbstractHeaderCheck

Parameters:
aFileName - the file that contains the header to check against.


setMultiLines

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

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