public class DeclarationOrderCheck extends AbstractCheck
Checks that the parts of a class or interface declaration appear in the order suggested by the Code Conventions for the Java Programming Language.
According to Code Conventions for the Java Programming Language, the parts of a class or interface declaration should appear in the following order:
Purpose of ignore* option is to ignore related violations, however it still impacts on other class members.
ATTENTION: the check skips class fields which have forward references from validation due to the fact that we have Checkstyle's limitations to clearly detect user intention of fields location and grouping. For example:
public class A { private double x = 1.0; private double y = 2.0; public double slope = x / y; // will be skipped from validation due to forward reference }
ignoreConstructors
- control whether to ignore constructors.
Type is boolean
.
Default value is false
.
ignoreModifiers
- control whether to ignore modifiers (fields, ...).
Type is boolean
.
Default value is false
.
To configure the check:
<module name="DeclarationOrder"/>
With default options:
class K { int a; void m(){} K(){} <-- "Constructor definition in wrong order" int b; <-- "Instance variable definition in wrong order" }
With ignoreConstructors option:
class K { int a; void m(){} K(){} int b; <-- "Instance variable definition in wrong order" }
With ignoreConstructors option and without a method definition in a source class:
class K { int a; K(){} int b; <-- "Instance variable definition in wrong order" }
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
declaration.order.access
declaration.order.constructor
declaration.order.instance
declaration.order.static
AutomaticBean.OutputStreamOptions
Modifier and Type | Field and Description |
---|---|
static String |
MSG_ACCESS
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_CONSTRUCTOR
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_INSTANCE
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_STATIC
A key is pointing to the warning message text in "messages.properties"
file.
|
Constructor and Description |
---|
DeclarationOrderCheck() |
Modifier and Type | Method and Description |
---|---|
void |
beginTree(DetailAST rootAST)
Called before the starting to process a tree.
|
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 |
leaveToken(DetailAST ast)
Called after all the child nodes have been process.
|
void |
setIgnoreConstructors(boolean ignoreConstructors)
Setter to control whether to ignore constructors.
|
void |
setIgnoreModifiers(boolean ignoreModifiers)
Setter to control whether to ignore modifiers (fields, ...).
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, log, log, log, setFileContents, setTabWidth, setTokens
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
configure, contextualize, getConfiguration, setupChild
public static final String MSG_CONSTRUCTOR
public static final String MSG_STATIC
public static final String MSG_INSTANCE
public static final String MSG_ACCESS
public DeclarationOrderCheck()
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 beginTree(DetailAST rootAST)
AbstractCheck
beginTree
in class AbstractCheck
rootAST
- the root of the treepublic void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processpublic void leaveToken(DetailAST ast)
AbstractCheck
leaveToken
in class AbstractCheck
ast
- the token leavingpublic void setIgnoreConstructors(boolean ignoreConstructors)
ignoreConstructors
- whether to ignore constructors.public void setIgnoreModifiers(boolean ignoreModifiers)
ignoreModifiers
- whether to ignore modifiers.Copyright © 2001–2020. All rights reserved.