|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.puppycrawl.tools.checkstyle.api.AutomaticBean com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter com.puppycrawl.tools.checkstyle.api.Check com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck
Checks correct indentation of Java Code.
The basic idea behind this is that while pretty printers are sometimes convienent 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 are followed.
Implementation -- Basically, this check requests visitation for all handled token types (those tokens registered in the HandlerFactory). When visitToken is called, a new ExpressionHandler is created for the AST and pushed onto the mHandlers stack. The new handler then checks the indentation for the currently visiting AST. When leaveToken is called, the ExpressionHandler is popped from the stack.
While on the stack the ExpressionHandler can be queried for the indentation level it suggests for children as well as for other values.
While an ExpressionHandler checks the indentation level of its own AST, it typically also checks surrounding ASTs. For instance, a while loop handler checks the while loop as well as the braces and immediate children.
- handler class -to-> ID mapping kept in Map - parent passed in during construction - suggest child indent level - allows for some tokens to be on same line (ie inner classes OBJBLOCK) and not increase indentation level - looked at using double dispatch for suggestedChildLevel(), but it doesn't seem worthwhile, at least now - both tabs and spaces are considered whitespace in front of the line... tabs are converted to spaces - block parents with parens -- for, while, if, etc... -- are checked that they match the level of the parent
Constructor Summary | |
IndentationCheck()
Creates a new instance of IndentationCheck. |
Method Summary | |
void |
beginTree(DetailAST aAst)
Called before the starting to process a tree. |
int |
getBasicOffset()
Get the basic offset. |
int |
getBraceAdjustement()
Get the brace adjustment amount. |
int |
getCaseIndent()
Get the case indentation level. |
int[] |
getDefaultTokens()
Get the tokens that this check will handle. |
int |
getIndentationTabWidth()
Get the width of a tab. |
void |
indentationLog(int aLine,
java.lang.String aKey,
java.lang.Object[] aArgs)
Log an error message. |
void |
leaveToken(DetailAST aAST)
Called after all the child nodes have been process. |
void |
setBasicOffset(int aBasicOffset)
Set the basic offset. |
void |
setBraceAdjustment(int aAdjustmentAmount)
Adjusts brace indentation (positive offset). |
void |
setCaseIndent(int aAmount)
Set the case indentation level. |
void |
visitToken(DetailAST aAST)
Called to process a token. |
Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check |
destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens |
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter |
getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, setSeverity |
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean |
configure, contextualize, finishLocalSetup, getConfiguration, setupChild |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public IndentationCheck()
Method Detail |
public void setBasicOffset(int aBasicOffset)
aBasicOffset
- the number of tabs or spaces to indentpublic int getBasicOffset()
public void setBraceAdjustment(int aAdjustmentAmount)
aAdjustmentAmount
- the brace offsetpublic int getBraceAdjustement()
public void setCaseIndent(int aAmount)
aAmount
- the case indentation levelpublic int getCaseIndent()
public void indentationLog(int aLine, java.lang.String aKey, java.lang.Object[] aArgs)
aLine
- the line number where the error was foundaKey
- the message that describes the erroraArgs
- the details of the messageMessageFormat
public int getIndentationTabWidth()
public int[] getDefaultTokens()
getDefaultTokens
in class Check
TokenTypes
public void beginTree(DetailAST aAst)
Check
beginTree
in class Check
aAst
- the root of the treeCheck
public void visitToken(DetailAST aAST)
Check
visitToken
in class Check
aAST
- the token to processCheck
public void leaveToken(DetailAST aAST)
Check
leaveToken
in class Check
aAST
- the token leavingCheck
|
Back to the Checkstyle Home Page | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |