Class AvoidEscapedUnicodeCharactersCheck
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractCheck
com.puppycrawl.tools.checkstyle.checks.AvoidEscapedUnicodeCharactersCheck
- All Implemented Interfaces:
Configurable,Contextualizable
Restricts using
Unicode escapes
(such as \u221e). 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.
- Since:
- 5.8
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final PatternRegular expression for all escaped chars.private booleanAllow use escapes if trail comment is present.private booleanAllow use escapes for non-printable, control characters.private booleanAllow if all characters in literal are escaped.private booleanAllow use escapes for non-printable, whitespace characters.private static final PatternRegular expression for escaped backslash.static final StringA key is pointing to the warning message text in "messages.properties" file.private static final PatternRegular expression for non-printable unicode chars.Map of Pending Violations.private static final PatternRegular expression Unicode control characters.private static final PatternRegular expression for Unicode chars. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled before the starting to process a tree.private voidcheckComment(DetailAST comment) Checks if a comment clears any pending violations on the same line.private voidcheckLiteral(DetailAST ast) Checks if the literal has Unicode char and should be reported.private static intcountMatches(Pattern pattern, String target) Count regexp matches into String literal.voidfinishTree(DetailAST rootAST) Called after finished processing a tree.int[]The configurable token set.int[]Returns the default token a check is interested in.int[]The tokens that this check must be registered for.private static booleanhasUnicodeChar(String literal) Checks if literal has Unicode chars.private booleanisAllCharactersEscaped(String literal) Checks if all characters in String literal is escaped.booleanWhether comment nodes are required or not.private static booleanisOnlyUnicodeValidChars(String literal, Pattern pattern) Check if String literal contains Unicode control chars.private static booleanisTrailingComment(DetailAST commentNode) Checks if a comment is trailing (has no code after it on the same line).final voidsetAllowByTailComment(boolean allow) Setter to allow use escapes if trail comment is present.final voidsetAllowEscapesForControlCharacters(boolean allow) Setter to allow use escapes for non-printable, control characters.final voidsetAllowIfAllCharactersEscaped(boolean allow) Setter to allow if all characters in literal are escaped.final voidsetAllowNonPrintableEscapes(boolean allow) Setter to allow use escapes for non-printable, whitespace characters.voidvisitToken(DetailAST ast) Called to process a token.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, destroy, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
MSG_KEY
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
UNICODE_REGEXP
Regular expression for Unicode chars. -
UNICODE_CONTROL
Regular expression Unicode control characters.- See Also:
-
ALL_ESCAPED_CHARS
Regular expression for all escaped chars. See EscapeSequence -
ESCAPED_BACKSLASH
Regular expression for escaped backslash. -
NON_PRINTABLE_CHARS
Regular expression for non-printable unicode chars. -
pendingViolations
Map of Pending Violations. Key: Line number of the violation. Value: List of literal AST nodes on that line pending validation. -
allowEscapesForControlCharacters
Allow use escapes for non-printable, control characters. -
allowByTailComment
Allow use escapes if trail comment is present. -
allowIfAllCharactersEscaped
Allow if all characters in literal are escaped. -
allowNonPrintableEscapes
Allow use escapes for non-printable, whitespace characters.
-
-
Constructor Details
-
AvoidEscapedUnicodeCharactersCheck
public AvoidEscapedUnicodeCharactersCheck()
-
-
Method Details
-
setAllowEscapesForControlCharacters
Setter to allow use escapes for non-printable, control characters.- Parameters:
allow- user's value.- Since:
- 5.8
-
setAllowByTailComment
Setter to allow use escapes if trail comment is present.- Parameters:
allow- user's value.- Since:
- 5.8
-
setAllowIfAllCharactersEscaped
Setter to allow if all characters in literal are escaped.- Parameters:
allow- user's value.- Since:
- 5.8
-
setAllowNonPrintableEscapes
Setter to allow use escapes for non-printable, whitespace characters.- Parameters:
allow- user's value.- Since:
- 5.8
-
getDefaultTokens
Description copied from class:AbstractCheckReturns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.- Specified by:
getDefaultTokensin classAbstractCheck- Returns:
- the default tokens
- See Also:
-
getAcceptableTokens
Description copied from class:AbstractCheckThe configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.- Specified by:
getAcceptableTokensin classAbstractCheck- Returns:
- the token set this check is designed for.
- See Also:
-
getRequiredTokens
Description copied from class:AbstractCheckThe tokens that this check must be registered for.- Specified by:
getRequiredTokensin classAbstractCheck- Returns:
- the token set this must be registered for.
- See Also:
-
isCommentNodesRequired
Description copied from class:AbstractCheckWhether comment nodes are required or not.- Overrides:
isCommentNodesRequiredin classAbstractCheck- Returns:
- false as a default value.
-
beginTree
Description copied from class:AbstractCheckCalled before the starting to process a tree. Ideal place to initialize information that is to be collected whilst processing a tree.- Overrides:
beginTreein classAbstractCheck- Parameters:
rootAST- the root of the tree
-
visitToken
Description copied from class:AbstractCheckCalled to process a token.- Overrides:
visitTokenin classAbstractCheck- Parameters:
ast- the token to process
-
finishTree
Description copied from class:AbstractCheckCalled after finished processing a tree. Ideal place to report on information collected whilst processing a tree.- Overrides:
finishTreein classAbstractCheck- Parameters:
rootAST- the root of the tree
-
checkLiteral
Checks if the literal has Unicode char and should be reported. If violation is found, it is added to pendingViolations.- Parameters:
ast- literal token.
-
checkComment
Checks if a comment clears any pending violations on the same line.- Parameters:
comment- comment token.
-
isTrailingComment
Checks if a comment is trailing (has no code after it on the same line).- Parameters:
commentNode- the comment AST node- Returns:
- true if it is trailing
-
hasUnicodeChar
Checks if literal has Unicode chars.- Parameters:
literal- String literal.- Returns:
- true if literal has Unicode chars.
-
isOnlyUnicodeValidChars
Check if String literal contains Unicode control chars.- Parameters:
literal- String literal.pattern- RegExp for valid characters.- Returns:
- true, if String literal contains Unicode control chars.
-
countMatches
Count regexp matches into String literal.- Parameters:
pattern- pattern.target- String literal.- Returns:
- count of regexp matches.
-
isAllCharactersEscaped
Checks if all characters in String literal is escaped.- Parameters:
literal- current literal.- Returns:
- true if all characters in String literal is escaped.
-