public class AvoidEscapedUnicodeCharactersCheck extends Check
Restrict using Unicode escapes (e.g. ∞). It is possible to allow using escapes for non-printable(control) characters. Also, this check can be configured to allow using escapes if trail comment is present. By the option it is possible to allow using escapes if literal contains only them. By the option it is possible to allow using escapes for space literals.
Examples of using Unicode:
String unitAbbrev = "μs"; //Best: perfectly clear even without a comment. String unitAbbrev = "μs"; //Poor: the reader has no idea what this is.
An example of how to configure the check is:
<module name="AvoidEscapedUnicodeCharacters"/>
An example of non-printable(control) characters.
return '' + content; // byte order mark
An example of how to configure the check to allow using escapes for non-printable(control) characters:
<module name="AvoidEscapedUnicodeCharacters"> <property name="allowEscapesForControlCharacters" value="true"/> </module>
Example of using escapes with trail comment:
String unitAbbrev = "μs"; // Greek letter mu, "s"
An example of how to configure the check to allow using escapes if trail comment is present:
<module name="AvoidEscapedUnicodeCharacters"> <property name="allowByTailComment" value="true"/> </module>
Example of using escapes if literal contains only them:
String unitAbbrev = "μμμ";
An example of how to configure the check to allow escapes if literal contains only them:
<module name="AvoidEscapedUnicodeCharacters"> <property name="allowIfAllCharactersEscaped" value="true"/> </module>
An example of how to configure the check to allow non-printable escapes:
<module name="AvoidEscapedUnicodeCharacters"> <property name="allowNonPrintableEscapes" value="true"/> </module>
Constructor and Description |
---|
AvoidEscapedUnicodeCharactersCheck() |
Modifier and Type | Method and Description |
---|---|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
void |
setAllowByTailComment(boolean allow)
Set allowByTailComment.
|
void |
setAllowEscapesForControlCharacters(boolean allow)
Set allowIfAllCharactersEscaped.
|
void |
setAllowIfAllCharactersEscaped(boolean allow)
Set allowIfAllCharactersEscaped.
|
void |
setAllowNonPrintableEscapes(boolean allow)
Set allowSpaceEscapes.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, 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 AvoidEscapedUnicodeCharactersCheck()
public final void setAllowEscapesForControlCharacters(boolean allow)
allow
- user's value.public final void setAllowByTailComment(boolean allow)
allow
- user's value.public final void setAllowIfAllCharactersEscaped(boolean allow)
allow
- user's value.public final void setAllowNonPrintableEscapes(boolean allow)
allow
- user's value.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.