public class TrailingCommentCheck extends AbstractFormatCheck
The check to ensure that requires that comments be the only thing on a line.
For the case of // comments that means that the only thing that should
precede it is whitespace.
It doesn't check comments if they do not end line, i.e. it accept
the following:
Thread.sleep( 10 <some comment here> );
Format property is intended to deal with the "} // while" example.
Rationale: Steve McConnel in "Code Complete" suggests that endline comments are a bad practice. An end line comment would be one that is on the same line as actual code. For example:
a = b + c; // Some insightful comment d = e / f; // Another comment for this lineQuoting "Code Complete" for the justification:
To configure the check so it enforces only comment on a line:
<module name="TrailingComment"> <property name="format" value="^\\s*$"/> </module>
Constructor and Description |
---|
TrailingCommentCheck()
Creates new instance of the check.
|
Modifier and Type | Method and Description |
---|---|
void |
beginTree(DetailAST rootAST)
Called before the starting to process a tree.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
void |
setLegalComment(String format)
Sets patter for legal trailing comments.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
getFormat, getRegexp, setCompileFlags, setFormat
destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLine, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
public TrailingCommentCheck() throws org.apache.commons.beanutils.ConversionException
org.apache.commons.beanutils.ConversionException
- unable to parse DEFAULT_FORMAT.public void setLegalComment(String format) throws org.apache.commons.beanutils.ConversionException
format
- format to set.org.apache.commons.beanutils.ConversionException
- unable to parse a given format.public int[] getDefaultTokens()
Check
getDefaultTokens
in class Check
TokenTypes
public void visitToken(DetailAST ast)
Check
visitToken
in class Check
ast
- the token to processCopyright © 2001–2015. All rights reserved.