|
|||||||||
| Home >> All >> com >> puppycrawl >> tools >> checkstyle >> [ checks overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.puppycrawl.tools.checkstyle.checks
Class HeaderCheck

java.lang.Objectcom.puppycrawl.tools.checkstyle.api.AutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.Check
com.puppycrawl.tools.checkstyle.checks.HeaderCheck
- All Implemented Interfaces:
- com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable
- Direct Known Subclasses:
- RegexpHeaderCheck
- public class HeaderCheck
- extends com.puppycrawl.tools.checkstyle.api.Check
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>
| Field Summary | |
private static int[] |
EMPTY_INT_ARRAY
empty array to avoid instantiations |
private java.lang.String[] |
mHeaderLines
the lines of the header file |
private int[] |
mIgnoreLines
the header lines to ignore in the check, sorted |
| Fields inherited from class com.puppycrawl.tools.checkstyle.api.Check |
|
| Fields inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter |
|
| Fields inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean |
|
| Constructor Summary | |
HeaderCheck()
|
|
| Method Summary | |
void |
beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST)
Called before the starting to process a tree. |
protected void |
finishLocalSetup()
Checks that required args were specified. |
int[] |
getDefaultTokens()
Returns the default token a check is interested in. |
protected java.lang.String[] |
getHeaderLines()
Return the header lines to check against. |
private boolean |
isIgnoreLine(int aLineNo)
|
protected boolean |
isMatch(int aLineNumber)
Checks if a code line matches the required header line. |
void |
setHeaderFile(java.lang.String aFileName)
Set the header file to check against. |
void |
setIgnoreLines(int[] aList)
Set the lines numbers to ignore in the header check. |
| Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check |
destroy, finishTree, getAcceptableTokens, getClassLoader, 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, setSeverity |
| Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean |
configure, contextualize, getConfiguration, setupChild |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
EMPTY_INT_ARRAY
private static final int[] EMPTY_INT_ARRAY
- empty array to avoid instantiations
mHeaderLines
private java.lang.String[] mHeaderLines
- the lines of the header file
mIgnoreLines
private int[] mIgnoreLines
- the header lines to ignore in the check, sorted
| Constructor Detail |
HeaderCheck
public HeaderCheck()
| Method Detail |
getDefaultTokens
public int[] getDefaultTokens()
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check - Returns the default token a check is interested in. Only used if the
configuration for a check does not define the tokens.
finishLocalSetup
protected final void finishLocalSetup()
throws com.puppycrawl.tools.checkstyle.api.CheckstyleException
- Checks that required args were specified.
beginTree
public void beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST)
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check - Called before the starting to process a tree. Ideal place to initialise
information that is to be collected whilst processing a tree.
isIgnoreLine
private boolean isIgnoreLine(int aLineNo)
isMatch
protected boolean isMatch(int aLineNumber)
- Checks if a code line matches the required header line.
setHeaderFile
public void setHeaderFile(java.lang.String aFileName) throws org.apache.commons.beanutils.ConversionException
- Set the header file to check against.
setIgnoreLines
public void setIgnoreLines(int[] aList)
- Set the lines numbers to ignore in the header check.
getHeaderLines
protected java.lang.String[] getHeaderLines()
- Return the header lines to check against.
|
|||||||||
| Home >> All >> com >> puppycrawl >> tools >> checkstyle >> [ checks overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC