public class IndentationCheck extends AbstractCheck
Checks correct indentation of Java code.
The idea behind this is that while pretty printers are sometimes convenient for bulk reformats of legacy code, they often either aren't configurable enough or just can't anticipate how format should be done. Sometimes this is personal preference, other times it is practical experience. In any case, this check should just ensure that a minimal set of indentation rules is followed.
basicOffset - Specify how far new indentation level should be
indented when on the next line.
Default value is 4.
braceAdjustment - Specify how far a braces should be indented
when on the next line.
Default value is 0.
caseIndent - Specify how far a case label should be indented
when on next line.
Default value is 4.
throwsIndent - Specify how far a throws clause should be
indented when on next line.
Default value is 4.
arrayInitIndent - Specify how far an array initialisation
should be indented when on next line. Default value is 4.
lineWrappingIndentation - Specify how far continuation line
should be indented when line-wrapping is present.
Default value is 4.
forceStrictCondition - Force strict indent level in line
wrapping case. If value is true, line wrap indent have to be same as
lineWrappingIndentation parameter. If value is false, line wrap indent
could be bigger on any value user would like.
Default value is false.
To configure the check:
<module name="Indentation"/>
To configure the check to enforce the indentation style recommended by Oracle:
<module name="Indentation"> <property name="caseIndent" value="0"/> </module>
To configure the Check to enforce strict condition in line-wrapping validation.
<module name="Indentation"> <property name="forceStrictCondition" value="true"/> </module>
Such config doesn't allow next cases:
void foo(String aFooString,
int aFooInt) {} // indent:8 ; expected: 4; warn, because 8 != 4
But if forceStrictCondition = false, this code is valid:
void foo(String aFooString,
int aFooInt) {} // indent:8 ; expected: > 4; ok, because 8 > 4
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MSG_CHILD_ERROR
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_CHILD_ERROR_MULTI
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_ERROR
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_ERROR_MULTI
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
IndentationCheck() |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTree(DetailAST ast)
Called before the starting to process a tree.
|
int[] |
getAcceptableTokens()
The configurable token set.
|
int |
getArrayInitIndent()
Getter to query how far an array initialisation should be indented when on next line.
|
int |
getBasicOffset()
Getter to query how far new indentation level should be indented when on the next line.
|
int |
getBraceAdjustment()
Getter to query how far a braces should be indented when on the next line.
|
int |
getCaseIndent()
Getter to query how far a case label should be indented when on next line.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
HandlerFactory |
getHandlerFactory()
Accessor for the handler factory.
|
int |
getIndentationTabWidth()
Get the width of a tab.
|
LineWrappingHandler |
getLineWrappingHandler()
Accessor for the line wrapping handler.
|
int |
getLineWrappingIndentation()
Getter to query how far continuation line should be indented when line-wrapping is present.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
int |
getThrowsIndent()
Getter to query how far a throws clause should be indented when on next line.
|
void |
indentationLog(int line,
java.lang.String key,
java.lang.Object... args)
Log a violation message.
|
boolean |
isForceStrictCondition()
Getter to query strict indent level in line wrapping case.
|
void |
leaveToken(DetailAST ast)
Called after all the child nodes have been process.
|
void |
setArrayInitIndent(int arrayInitIndent)
Setter to specify how far an array initialisation should be indented when on next line.
|
void |
setBasicOffset(int basicOffset)
Setter to specify how far new indentation level should be indented when on the next line.
|
void |
setBraceAdjustment(int adjustmentAmount)
Setter to specify how far a braces should be indented when on the next line.
|
void |
setCaseIndent(int amount)
Setter to specify how far a case label should be indented when on next line.
|
void |
setForceStrictCondition(boolean value)
Setter to force strict indent level in line wrapping case.
|
void |
setLineWrappingIndentation(int lineWrappingIndentation)
Setter to specify how far continuation line should be indented when line-wrapping is present.
|
void |
setThrowsIndent(int throwsIndent)
Setter to specify how far a throws clause should be indented when on next line.
|
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, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final java.lang.String MSG_ERROR
public static final java.lang.String MSG_ERROR_MULTI
public static final java.lang.String MSG_CHILD_ERROR
public static final java.lang.String MSG_CHILD_ERROR_MULTI
public IndentationCheck()
public boolean isForceStrictCondition()
public void setForceStrictCondition(boolean value)
value - user's value of forceStrictCondition.public void setBasicOffset(int basicOffset)
basicOffset - the number of tabs or spaces to indentpublic int getBasicOffset()
public void setBraceAdjustment(int adjustmentAmount)
adjustmentAmount - the brace offsetpublic int getBraceAdjustment()
public void setCaseIndent(int amount)
amount - the case indentation levelpublic int getCaseIndent()
public void setThrowsIndent(int throwsIndent)
throwsIndent - the throws indentation levelpublic int getThrowsIndent()
public void setArrayInitIndent(int arrayInitIndent)
arrayInitIndent - the array initialisation indentation levelpublic int getArrayInitIndent()
public int getLineWrappingIndentation()
public void setLineWrappingIndentation(int lineWrappingIndentation)
lineWrappingIndentation - the line-wrapping indentation levelpublic void indentationLog(int line, java.lang.String key, java.lang.Object... args)
line - the line number where the violation was foundkey - the message that describes the violationargs - the details of the messageMessageFormatpublic int getIndentationTabWidth()
public int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void beginTree(DetailAST ast)
AbstractCheckbeginTree in class AbstractCheckast - the root of the treepublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processpublic void leaveToken(DetailAST ast)
AbstractCheckleaveToken in class AbstractCheckast - the token leavingpublic LineWrappingHandler getLineWrappingHandler()
public final HandlerFactory getHandlerFactory()
Copyright © 2001-2019. All Rights Reserved.