Class NewlineAtEndOfFileCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
-
- com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck
-
- All Implemented Interfaces:
Configurable,Contextualizable,FileSetCheck
public class NewlineAtEndOfFileCheck extends AbstractFileSetCheck
Checks that there is a newline at the end of each file.
An example of how to configure the check is:
<module name="NewlineAtEndOfFile"/>
This will check against the platform-specific default line separator.
It is also possible to enforce the use of a specific line-separator across platforms, with the 'lineSeparator' property:
<module name="NewlineAtEndOfFile"> <property name="lineSeparator" value="lf"/> </module>
Valid values for the 'lineSeparator' property are 'system' (system default), 'crlf' (windows), 'cr' (mac), 'lf' (unix) and 'lf_cr_crlf' (lf, cr or crlf).
-
-
Field Summary
Fields Modifier and Type Field Description private LineSeparatorOptionlineSeparatorThe line separator to check against.static java.lang.StringMSG_KEY_NO_NEWLINE_EOFA key is pointing to the warning message text in "messages.properties" file.static java.lang.StringMSG_KEY_UNABLE_OPENA key is pointing to the warning message text in "messages.properties" file.
-
Constructor Summary
Constructors Constructor Description NewlineAtEndOfFileCheck()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanendsWithNewline(java.io.RandomAccessFile randomAccessFile)Checks whether the content provided by the Reader ends with the platform specific line separator.protected voidprocessFiltered(java.io.File file, java.util.List<java.lang.String> lines)Called to process a file that matches the specified file extensions.voidsetLineSeparator(java.lang.String lineSeparatorParam)Sets the line separator to one of 'crlf', 'lf','cr', 'lf_cr_crlf' or 'system'.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
beginProcessing, destroy, finishProcessing, fireErrors, getFileExtensions, getMessageCollector, getMessageDispatcher, init, log, log, process, setFileExtensions, setMessageDispatcher
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, 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
-
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Configurable
configure
-
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Contextualizable
contextualize
-
-
-
-
Field Detail
-
MSG_KEY_UNABLE_OPEN
public static final java.lang.String MSG_KEY_UNABLE_OPEN
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_KEY_NO_NEWLINE_EOF
public static final java.lang.String MSG_KEY_NO_NEWLINE_EOF
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
lineSeparator
private LineSeparatorOption lineSeparator
The line separator to check against.
-
-
Method Detail
-
processFiltered
protected void processFiltered(java.io.File file, java.util.List<java.lang.String> lines)Description copied from class:AbstractFileSetCheckCalled to process a file that matches the specified file extensions.- Specified by:
processFilteredin classAbstractFileSetCheck- Parameters:
file- the file to be processedlines- an immutable list of the contents of the file.
-
setLineSeparator
public void setLineSeparator(java.lang.String lineSeparatorParam)
Sets the line separator to one of 'crlf', 'lf','cr', 'lf_cr_crlf' or 'system'.- Parameters:
lineSeparatorParam- The line separator to set- Throws:
java.lang.IllegalArgumentException- If the specified line separator is not one of 'crlf', 'lf', 'cr', 'lf_cr_crlf' or 'system'
-
endsWithNewline
private boolean endsWithNewline(java.io.RandomAccessFile randomAccessFile) throws java.io.IOExceptionChecks whether the content provided by the Reader ends with the platform specific line separator.- Parameters:
randomAccessFile- The reader for the content to check- Returns:
- boolean Whether the content ends with a line separator
- Throws:
java.io.IOException- When an IO error occurred while reading from the provided reader
-
-