com.puppycrawl.tools.checkstyle.checks

Class RegexpCheck

Implemented Interfaces:
Configurable, Contextualizable

public class RegexpCheck
extends AbstractFormatCheck

A check that makes sure that a specified pattern exists (or not) in the file.

An example of how to configure the check to make sure a copyright statement is included in the file (but without requirements on where in the file it should be):

 <module name="RequiredRegexp">
    <property name="format" value="This code is copyrighted"/>
 </module>
 

And to make sure the same statement appears at the beginning of the file.

 <module name="RequiredRegexp">
    <property name="format" value="\AThis code is copyrighted"/>
 </module>
 
Author:
Stan Quinn

Constructor Summary

RegexpCheck()
Instantiates an new RegexpCheck.

Method Summary

void
beginTree(DetailAST aRootAST)
int[]
getDefaultTokens()
String
getMessage()
Getter for message property.
void
setDuplicateLimit(int aDuplicateLimit)
Sets the maximum number of instances of required pattern allowed.
void
setErrorLimit(int aErrorLimit)
Sets the limit on the number of errors to report.
void
setIgnoreComments(boolean aIgnoreComments)
Sets if matches within comments should be ignored.
void
setIllegalPattern(boolean aIllegalPattern)
Sets if pattern is illegal, otherwise pattern is required.
void
setMessage(String aMessage)
Setter for message property.

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

getFormat, getRegexp, setCompileFlags, setFormat

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

getId, getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, log, log, setId, setSeverity

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

configure, contextualize, finishLocalSetup, getConfiguration, setupChild

Constructor Details

RegexpCheck

public RegexpCheck()
Instantiates an new RegexpCheck.

Method Details

beginTree

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

getDefaultTokens

public int[] getDefaultTokens()
Overrides:
getDefaultTokens in interface Check

getMessage

public String getMessage()
Getter for message property. I'm not sure if this gets used by anything outside, I just included it because GenericIllegalRegexp had it, it's being used in logMessage() so it's covered in EMMA.
Returns:
custom message to be used in report.

setDuplicateLimit

public void setDuplicateLimit(int aDuplicateLimit)
Sets the maximum number of instances of required pattern allowed.
Parameters:
aDuplicateLimit - negative values mean no duplicate checking, any positive value is used as the limit.

setErrorLimit

public void setErrorLimit(int aErrorLimit)
Sets the limit on the number of errors to report.
Parameters:
aErrorLimit - the number of errors to report.

setIgnoreComments

public void setIgnoreComments(boolean aIgnoreComments)
Sets if matches within comments should be ignored.
Parameters:
aIgnoreComments - True if comments should be ignored.

setIllegalPattern

public void setIllegalPattern(boolean aIllegalPattern)
Sets if pattern is illegal, otherwise pattern is required.
Parameters:
aIllegalPattern - True if pattern is not allowed.

setMessage

public void setMessage(String aMessage)
Setter for message property.
Parameters:
aMessage - custom message which should be used in report.