com.puppycrawl.tools.checkstyle.checks

Class RegexpCheck

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
voidbeginTree(DetailAST aRootAST)
{@inheritDoc}
int[]getDefaultTokens()
{@inheritDoc}
StringgetMessage()
Getter for message property.
PatterngetRegexp()
voidsetDuplicateLimit(int aDuplicateLimit)
Sets the maximum number of instances of required pattern allowed.
voidsetErrorLimit(int aErrorLimit)
Sets the limit on the number of errors to report.
voidsetIgnoreComments(boolean aIgnoreComments)
Sets if matches within comments should be ignored.
voidsetIllegalPattern(boolean aIllegalPattern)
Sets if pattern is illegal, otherwise pattern is required.
voidsetMessage(String aMessage)
Setter for message property.

Constructor Detail

RegexpCheck

public RegexpCheck()
Instantiates an new RegexpCheck.

Method Detail

beginTree

public void beginTree(DetailAST aRootAST)
{@inheritDoc}

getDefaultTokens

public int[] getDefaultTokens()
{@inheritDoc}

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.

getRegexp

public Pattern getRegexp()

Returns: the regexp to match against

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.