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.
allowedAbbreviationLength specifies how many consecutive capital letters are
allowed in the identifier.
A value of 3 indicates that up to 4 consecutive capital letters are allowed,
one after the other, before a violation is printed. The identifier 'MyTEST' would be
allowed, but 'MyTESTS' would not be.
A value of 0 indicates that only 1 consecutive capital letter is allowed. This
is what should be used to enforce strict camel casing. The identifier 'MyTest' would
be allowed, but 'MyTEst' would not be.
allowedAbbreviationLength - Indicate the number of consecutive capital
letters allowed in targeted identifiers (abbreviations in the classes, interfaces, variables
and methods names, ... ). Default value is 3.
allowedAbbreviations - Specify list of abbreviations that must be skipped for
checking. Abbreviations should be separated by comma. Default value is {}.
ignoreFinal - Allow to skip variables with final modifier. Default
value is true.
ignoreStatic - Allow to skip variables with static modifier. Default
value is true.
ignoreOverriddenMethods - Allow to ignore methods tagged with @Override
annotation (that usually mean inherited name). Default value is true.
tokens - tokens to check Default value is:
CLASS_DEF,
INTERFACE_DEF,
ENUM_DEF,
ANNOTATION_DEF,
ANNOTATION_FIELD_DEF,
PARAMETER_DEF,
VARIABLE_DEF,
METHOD_DEF.
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>
AutomaticBean.OutputStreamOptions| 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()
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.
|
void |
setAllowedAbbreviationLength(int allowedAbbreviationLength)
Setter to indicate the number of consecutive capital letters allowed
in targeted identifiers (abbreviations in the classes, interfaces,
variables and methods names, ...
|
void |
setAllowedAbbreviations(java.lang.String... allowedAbbreviations)
Setter to specify list of abbreviations that must be skipped for checking.
|
void |
setIgnoreFinal(boolean ignoreFinal)
Setter to allow to skip variables with
final modifier. |
void |
setIgnoreOverriddenMethods(boolean ignoreOverriddenMethods)
Setter to allow to ignore methods tagged with
@Override
annotation (that usually mean inherited name). |
void |
setIgnoreStatic(boolean ignoreStatic)
Setter to allow to skip variables with
static modifier. |
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setClassLoader, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final java.lang.String MSG_KEY
public AbbreviationAsWordInNameCheck()
public void setIgnoreFinal(boolean ignoreFinal)
final modifier.ignoreFinal - Defines if ignore variables with 'final' modifier or not.public void setIgnoreStatic(boolean ignoreStatic)
static modifier.ignoreStatic - Defines if ignore variables with 'static' modifier or not.public void setIgnoreOverriddenMethods(boolean ignoreOverriddenMethods)
@Override
annotation (that usually mean inherited name).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()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processCopyright © 2001-2018. All Rights Reserved.