public class ModifierOrderCheck extends AbstractCheck
Checks that the order of modifiers conforms to the suggestions in the Java Language specification, sections 8.1.1, 8.3.1 and 8.4.3. The correct order is:
Rationale: Code is easier to read if everybody follows a standard.
An example of how to configure the check is:
<module name="ModifierOrder"/>
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
JLS_ORDER
The order of modifiers as suggested in sections 8.1.1,
8.3.1 and 8.4.3 of the JLS.
|
static java.lang.String |
MSG_ANNOTATION_ORDER
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_MODIFIER_ORDER
A key is pointing to the warning message text in "messages.properties"
file.
|
Constructor and Description |
---|
ModifierOrderCheck() |
Modifier and Type | Method and Description |
---|---|
private static DetailAST |
checkOrderSuggestedByJls(java.util.List<DetailAST> modifiers)
Checks if the modifiers were added in the order suggested
in the Java language specification.
|
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.
|
private static boolean |
isAnnotationOnType(DetailAST modifier)
Checks whether annotation on type takes place.
|
private static DetailAST |
skipAnnotations(java.util.Iterator<DetailAST> modifierIterator)
Skip all annotations in modifier block.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
public static final java.lang.String MSG_ANNOTATION_ORDER
public static final java.lang.String MSG_MODIFIER_ORDER
private static final java.lang.String[] JLS_ORDER
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 AbstractCheck
ast
- the token to processprivate static DetailAST checkOrderSuggestedByJls(java.util.List<DetailAST> modifiers)
modifiers
- list of modifier AST tokensprivate static DetailAST skipAnnotations(java.util.Iterator<DetailAST> modifierIterator)
modifierIterator
- iterator for collection of modifiersprivate static boolean isAnnotationOnType(DetailAST modifier)
modifier
- modifier token.