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.OutputStreamOptionsMSG_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.
|
setFormatbeginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic LambdaParameterNameCheck()
LambdaParameterNameCheck.public int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractNameCheckast - the token to processprotected boolean mustCheckName(DetailAST ast)
AbstractNameCheckmustCheckName in class AbstractNameCheckast - the AST to check.Copyright © 2001–2020. All rights reserved.