public class RegexpSinglelineCheck extends AbstractFileSetCheck
Checks that a specified pattern matches a single line in any file type.
Rationale: This check can be used to prototype checks and to find common bad
practice such as calling ex.printStacktrace(),
System.out.println(), System.exit(), etc.
format - Specify the format of the regular expression to match.
Default value is "$.".
message - Specify the message which is used to notify about
violations, if empty then default (hard-coded) message is used.
Default value is null.
ignoreCase - Control whether to ignore case when searching.
Default value is false.
minimum - Specify the minimum number of matches required in each file.
Default value is 0.
maximum - Specify the maximum number of matches required in each file.
Default value is 0.
fileExtensions - Specify the file type extension of files to process.
Default value is all files.
To configure the check to find trailing whitespace at the end of a line:
<module name="RegexpSingleline"> <!-- \s matches whitespace character, $ matches end of line. --> <property name="format" value="\s+$"/> </module>
To configure the check to find trailing whitespace at the end of a line, with some slack of allowing two occurrences per file:
<module name="RegexpSingleline"> <property name="format" value="\s+$"/> <!-- next line not required as 0 is the default --> <property name="minimum" value="0"/> <property name="maximum" value="2"/> </module>
An example of how to configure the check to make sure a copyright statement is included in the file:
<module name="RegexpSingleline"> <property name="format" value="This file is copyrighted"/> <property name="minimum" value="1"/> <!-- Need to specify a maximum, so 10 times is more than enough. --> <property name="maximum" value="10"/> </module>
AutomaticBean.OutputStreamOptions| Constructor and Description |
|---|
RegexpSinglelineCheck() |
| Modifier and Type | Method and Description |
|---|---|
void |
beginProcessing(java.lang.String charset)
Called when about to be called to process a set of files.
|
protected void |
processFiltered(java.io.File file,
FileText fileText)
Called to process a file that matches the specified file extensions.
|
void |
setFormat(java.lang.String format)
Setter to specify the format of the regular expression to match.
|
void |
setIgnoreCase(boolean ignoreCase)
Setter to control whether to ignore case when searching.
|
void |
setMaximum(int maximum)
Setter to specify the maximum number of matches required in each file.
|
void |
setMessage(java.lang.String message)
Setter to specify the message which is used to notify about violations,
if empty then default (hard-coded) message is used.
|
void |
setMinimum(int minimum)
Setter to specify the minimum number of matches required in each file.
|
addMessages, destroy, finishProcessing, fireErrors, getFileContents, getFileExtensions, getMessageDispatcher, getMessages, getTabWidth, init, log, log, process, setFileContents, setFileExtensions, setMessageDispatcher, setTabWidthfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigurecontextualizepublic RegexpSinglelineCheck()
public void beginProcessing(java.lang.String charset)
FileSetCheckbeginProcessing in interface FileSetCheckbeginProcessing in class AbstractFileSetCheckcharset - the character set used to read the files.protected void processFiltered(java.io.File file, FileText fileText)
AbstractFileSetCheckprocessFiltered in class AbstractFileSetCheckfile - the file to be processedfileText - the contents of the file.public void setFormat(java.lang.String format)
format - the format of the regular expression to match.public void setMessage(java.lang.String message)
message - the message to report for a match.public void setMinimum(int minimum)
minimum - the minimum number of matches required in each file.public void setMaximum(int maximum)
maximum - the maximum number of matches required in each file.public void setIgnoreCase(boolean ignoreCase)
ignoreCase - whether to ignore case when searching.Copyright © 2001-2020. All Rights Reserved.