com.puppycrawl.tools.checkstyle.checks
Class RegexpCheck

java.lang.Object
  extended by com.puppycrawl.tools.checkstyle.api.AutomaticBean
      extended by com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
          extended by com.puppycrawl.tools.checkstyle.api.Check
              extended by com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck
                  extended by com.puppycrawl.tools.checkstyle.checks.RegexpCheck
All 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)
          Called before the starting to process a tree.
 int[] getDefaultTokens()
          Returns the default token a check is interested in.
 String getMessage()
          Getter for message property.
 Pattern getRegexp()
           
 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, setFormat
 
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, log, log, log, setSeverity
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexpCheck

public RegexpCheck()
Instantiates an new RegexpCheck.

Method Detail

setMessage

public void setMessage(String aMessage)
Setter for message property.

Parameters:
aMessage - custom message which should be used in report.

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.

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.

setErrorLimit

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

Parameters:
aErrorLimit - the number of errors to 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.

getDefaultTokens

public int[] getDefaultTokens()
Returns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.

Specified by:
getDefaultTokens in class Check
Returns:
the default tokens
See Also:
TokenTypes

beginTree

public void beginTree(DetailAST aRootAST)
Called before the starting to process a tree. Ideal place to initialise information that is to be collected whilst processing a tree.

Overrides:
beginTree in class Check
Parameters:
aRootAST - the root of the tree

getRegexp

public Pattern getRegexp()
Overrides:
getRegexp in class AbstractFormatCheck
Returns:
the regexp to match against

Back to the Checkstyle Home Page