Class AlphabeticallyOrderedDefinitionsCheck
- All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable,com.puppycrawl.tools.checkstyle.api.Contextualizable
The configuration checks the ordering of variable and method definitions under classes and interfaces.
<module name="AlphabeticallyOrderedDefinitions"/>This check will error on a definition's line if it should be alphabetically before the last definition that has the same modifiers. For a definition that depends on a previous definition, if there are any ordering errors with definitions that come after the most recently declared definition that it depends on, the check will error. However, if the definition is a special variable, the check will pretend it's not there, so it won't be checked for alphabetical ordering, and will not affect variables declared after it. You can configure special variables by specifying the variable's type and identifier, separated by a space.
<module name="AlphabeticallyOrderedDefinitions">
<property name="specialVariables" value="Logger log, SpecialVariableType specialVariableName"/>
</module>
To specify non-access modifiers to ignore, you can configure the ignoredModifiers property with
final, static,
transient, native,
synchronized, volatile,
abstract, strictfp,
default, and annotation.
For example, the following configuration will check that definitions that have the same modifiers, but ignoring
whether they have static or final modifiers in common, are alphabetically ordered.
<module name="AlphabeticallyOrderedDefinitions">
<property name="ignoredModifiers" value="static, final"/>
</module>
For simplicity regarding the annotation modifier, the current implementation only checks whether a definition is
annotated and does not check what annotations the definition has, so if two definitions have the same modifiers and
one is annotated with @Override and the other with @Nonnull, they'll still be compared.
You can configure the ignoreVariables or ignoreMethods properties to not check variables or methods
respectively. For example, the following configuration doesn't check the ordering of methods:
<module name="AlphabeticallyOrderedDefinitions">
<property name="ignoreMethods" value="true"/>
</module>
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean.OutputStreamOptions -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]int[]int[]voidsetIgnoredModifiers(String... modifiers) voidsetIgnoreMethods(boolean shouldIgnore) voidsetIgnoreVariables(boolean shouldIgnore) voidsetSpecialVariables(String... variables) voidvisitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast) Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, 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
-
Constructor Details
-
AlphabeticallyOrderedDefinitionsCheck
public AlphabeticallyOrderedDefinitionsCheck()
-
-
Method Details
-
getDefaultTokens
public int[] getDefaultTokens()- Specified by:
getDefaultTokensin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getAcceptableTokens
public int[] getAcceptableTokens()- Specified by:
getAcceptableTokensin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getRequiredTokens
public int[] getRequiredTokens()- Specified by:
getRequiredTokensin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
setIgnoredModifiers
-
setIgnoreMethods
public void setIgnoreMethods(boolean shouldIgnore) -
setIgnoreVariables
public void setIgnoreVariables(boolean shouldIgnore) -
setSpecialVariables
-
visitToken
public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast) - Overrides:
visitTokenin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-