public class AbbreviationAsWordInNameCheck
extends AbstractCheck
The Check validate abbreviations(consecutive capital letters) length in identifier name, it also allows to enforce camel case naming. Please read more at Google Style Guide to get to know how to avoid long abbreviations in names.
Properties:
name | description | type | default value |
---|---|---|---|
allowedAbbreviationLength | indicates on the allowed amount of capital letters in targeted identifiers (abbreviations in the classes, interfaces, variables and methods names, ... ). | Integer | 3 |
allowedAbbreviations | list of abbreviations that must be skipped for checking. Abbreviations should be separated by comma, no spaces are allowed. | String Set | null |
ignoreFinal | allow to skip variables with final modifier. | Boolean | true |
ignoreStatic | allow to skip variables with static modifier. | Boolean | true |
ignoreOverriddenMethods | Allows to ignore methods tagged with @Override annotation (that usually mean inherited name). | Boolean | true |
tokens | tokens to check | subset of tokens CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, ENUM_CONSTANT_DEF. | CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF. |
Examples
Default configuration
<module name="AbbreviationAsWordInName"/>
To configure to check variables and classes identifiers, do not ignore variables with static modifier and allow no abbreviations (enforce camel case phrase) and allow no abbreviations to use (camel case phrase) and allow XML and URL abbreviations.
<module name="AbbreviationAsWordInName"> <property name="tokens" value="VARIABLE_DEF,CLASS_DEF"/> <property name="ignoreStatic" value="false"/> <property name="allowedAbbreviationLength" value="1"/> <property name="allowedAbbreviations" value="XML,URL"/> </module>
Example of usage
Error Messages
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
Package: com.puppycrawl.tools.checkstyle.checks.naming
Parent: TreeWalker
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MSG_KEY
Warning message key.
|
Constructor and Description |
---|
AbbreviationAsWordInNameCheck() |
Modifier and Type | Method and Description |
---|---|
int[] |
getAcceptableTokens() |
int[] |
getDefaultTokens() |
int[] |
getRequiredTokens() |
void |
setAllowedAbbreviationLength(int allowedAbbreviationLength)
Allowed abbreviation length in names.
|
void |
setAllowedAbbreviations(java.lang.String... allowedAbbreviations)
Set a list of abbreviations that must be skipped for checking.
|
void |
setIgnoreFinal(boolean ignoreFinal)
Sets ignore option for variables with 'final' modifier.
|
void |
setIgnoreOverriddenMethods(boolean ignoreOverriddenMethods)
Sets ignore option for methods with "@Override" annotation.
|
void |
setIgnoreStatic(boolean ignoreStatic)
Sets ignore option for variables with 'static' modifier.
|
void |
visitToken(DetailAST ast) |
public static final java.lang.String MSG_KEY
public void setIgnoreFinal(boolean ignoreFinal)
ignoreFinal
- Defines if ignore variables with 'final' modifier or not.public void setIgnoreStatic(boolean ignoreStatic)
ignoreStatic
- Defines if ignore variables with 'static' modifier or not.public void setIgnoreOverriddenMethods(boolean ignoreOverriddenMethods)
ignoreOverriddenMethods
- Defines if ignore methods with "@Override" annotation or not.public void setAllowedAbbreviationLength(int allowedAbbreviationLength)
allowedAbbreviationLength
- amount of allowed capital letters in abbreviation.public void setAllowedAbbreviations(java.lang.String... allowedAbbreviations)
allowedAbbreviations
- an string of abbreviations that must be skipped from checking,
each abbreviation separated by comma.public int[] getDefaultTokens()
public int[] getAcceptableTokens()
public int[] getRequiredTokens()
public void visitToken(DetailAST ast)