public class LambdaParameterNameCheck extends AbstractNameCheck
Checks lambda parameter names.
format
- Specifies valid identifiers.
Type is java.util.regex.Pattern
.
Default value is "^[a-z][a-zA-Z0-9]*$"
.
An example of how to configure the check is:
<module name="LambdaParameterName"/>
Code Example:
Function<String, String> function1 = s -> s.toLowerCase(); // OK Function<String, String> function2 = S -> S.toLowerCase(); // violation, name 'S' // must match pattern '^[a-z][a-zA-Z0-9]*$'
An example of how to configure the check for names that begin with a lower case letter, followed by letters is:
<module name="LambdaParameterName"> <property name="format" value="^[a-z]([a-zA-Z]+)*$"/> </module>
Code Example:
class MyClass { Function<String, String> function1 = str -> str.toUpperCase().trim(); // OK Function<String, String> function2 = _s -> _s.trim(); // violation, name '_s' // must match pattern '^[a-z]([a-zA-Z]+)*$' public boolean myMethod(String sentence) { return Stream.of(sentence.split(" ")) .map(word -> word.trim()) // OK .anyMatch(Word -> "in".equals(Word)); // violation, name 'Word' // must match pattern '^[a-z]([a-zA-Z]+)*$' } }
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
name.invalidPattern
AutomaticBean.OutputStreamOptions
MSG_INVALID_PATTERN
Constructor and Description |
---|
LambdaParameterNameCheck()
Creates new instance of
LambdaParameterNameCheck . |
Modifier and Type | Method and Description |
---|---|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
protected boolean |
mustCheckName(DetailAST ast)
Decides whether the name of an AST should be checked against
the format regexp.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
setFormat
beginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
configure, contextualize, getConfiguration, setupChild
public LambdaParameterNameCheck()
LambdaParameterNameCheck
.public int[] getDefaultTokens()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractNameCheck
ast
- the token to processprotected boolean mustCheckName(DetailAST ast)
AbstractNameCheck
mustCheckName
in class AbstractNameCheck
ast
- the AST to check.Copyright © 2001–2020. All rights reserved.