com.puppycrawl.tools.checkstyle.checks.indentation

Class ExpressionHandler

public abstract class ExpressionHandler extends Object

Abstract base class for all handlers.

Author: jrichard

Constructor Summary
ExpressionHandler(IndentationCheck aIndentCheck, String aTypeName, DetailAST aExpr, ExpressionHandler aParent)
Construct an instance of this handler with the given indentation check, name, abstract syntax tree, and parent handler.
Method Summary
protected voidcheckChildren(DetailAST aParent, int[] aTokenTypes, IndentLevel aStartLevel, boolean aFirstLineMatches, boolean aAllowNesting)
Check the indent level of the children of the specified parent expression.
protected voidcheckExpressionSubtree(DetailAST aTree, IndentLevel aLevel, boolean aFirstLineMatches, boolean aAllowNesting)
Check the indentation level for an expression subtree.
abstract voidcheckIndentation()
Check the indentation of the expression we are handling.
protected voidcheckLinesIndent(int aStartLine, int aEndLine, IndentLevel aIndentLevel)
Check the indentation of consecutive lines for the expression we are handling.
protected voidcheckLParen(DetailAST aLparen)
Check the indentation of the left parenthesis.
protected voidcheckModifiers()
Check the indentation level of modifiers.
protected voidcheckRParen(DetailAST aLparen, DetailAST aRparen)
Check the indentation of the right parenthesis.
protected intexpandedTabsColumnNo(DetailAST aAST)
Get the column number for the start of a given expression, expanding tabs out into spaces in the process.
protected voidfindSubtreeLines(LineSet aLines, DetailAST aTree, boolean aAllowNesting)
Find the set of lines for a given subtree.
protected intgetBasicOffset()
A shortcut for IndentationCheck property.
protected intgetBraceAdjustement()
A shortcut for IndentationCheck property.
protected intgetFirstLine(int aStartLine, DetailAST aTree)
Get the first line for a given expression.
protected IndentationCheckgetIndentCheck()
Accessor for the IndentCheck attribute.
IndentLevelgetLevel()
Get the indentation amount for this handler.
protected IndentLevelgetLevelImpl()
Compute the indentation amount for this handler.
protected intgetLineStart(DetailAST aAst)
Get the start of the line for the given expression.
protected intgetLineStart(String aLine)
Get the start of the specified line.
protected DetailASTgetMainAst()
Accessor for the MainAst attribute.
protected ExpressionHandlergetParent()
Accessor for the Parent attribute.
protected voidlogError(DetailAST aAst, String aSubtypeName, int aActualLevel)
Log an indentation error.
protected voidlogError(DetailAST aAst, String aSubtypeName, int aActualLevel, IndentLevel aExpectedLevel)
Log an indentation error.
protected booleanshouldIncreaseIndent()
protected booleanstartsLine(DetailAST aAst)
Determines if the given expression is at the start of a line.
IndentLevelsuggestedChildLevel(ExpressionHandler aChild)
Indentation level suggested for a child element.

Constructor Detail

ExpressionHandler

public ExpressionHandler(IndentationCheck aIndentCheck, String aTypeName, DetailAST aExpr, ExpressionHandler aParent)
Construct an instance of this handler with the given indentation check, name, abstract syntax tree, and parent handler.

Parameters: aIndentCheck the indentation check aTypeName the name of the handler aExpr the abstract syntax tree aParent the parent handler

Method Detail

checkChildren

protected final void checkChildren(DetailAST aParent, int[] aTokenTypes, IndentLevel aStartLevel, boolean aFirstLineMatches, boolean aAllowNesting)
Check the indent level of the children of the specified parent expression.

Parameters: aParent the parent whose children we are checking aTokenTypes the token types to check aStartLevel the starting indent level aFirstLineMatches whether or not the first line needs to match aAllowNesting whether or not nested children are allowed

checkExpressionSubtree

protected final void checkExpressionSubtree(DetailAST aTree, IndentLevel aLevel, boolean aFirstLineMatches, boolean aAllowNesting)
Check the indentation level for an expression subtree.

Parameters: aTree the expression subtree to check aLevel the indentation level aFirstLineMatches whether or not the first line has to match aAllowNesting whether or not subtree nesting is allowed

checkIndentation

public abstract void checkIndentation()
Check the indentation of the expression we are handling.

checkLinesIndent

protected final void checkLinesIndent(int aStartLine, int aEndLine, IndentLevel aIndentLevel)
Check the indentation of consecutive lines for the expression we are handling.

Parameters: aStartLine the first line to check aEndLine the last line to check aIndentLevel the required indent level

checkLParen

protected final void checkLParen(DetailAST aLparen)
Check the indentation of the left parenthesis.

Parameters: aLparen parenthesis to check

checkModifiers

protected final void checkModifiers()
Check the indentation level of modifiers.

checkRParen

protected final void checkRParen(DetailAST aLparen, DetailAST aRparen)
Check the indentation of the right parenthesis.

Parameters: aRparen parenthesis to check aLparen left parenthesis associated with aRparen

expandedTabsColumnNo

protected final int expandedTabsColumnNo(DetailAST aAST)
Get the column number for the start of a given expression, expanding tabs out into spaces in the process.

Parameters: aAST the expression to find the start of

Returns: the column number for the start of the expression

findSubtreeLines

protected final void findSubtreeLines(LineSet aLines, DetailAST aTree, boolean aAllowNesting)
Find the set of lines for a given subtree.

Parameters: aLines the set of lines to add to aTree the subtree to examine aAllowNesting whether or not to allow nested subtrees

getBasicOffset

protected final int getBasicOffset()
A shortcut for IndentationCheck property.

Returns: value of basicOffset property of IndentationCheck

getBraceAdjustement

protected final int getBraceAdjustement()
A shortcut for IndentationCheck property.

Returns: value of braceAdjustment property of IndentationCheck

getFirstLine

protected final int getFirstLine(int aStartLine, DetailAST aTree)
Get the first line for a given expression.

Parameters: aStartLine the line we are starting from aTree the expression to find the first line for

Returns: the first line of the expression

getIndentCheck

protected final IndentationCheck getIndentCheck()
Accessor for the IndentCheck attribute.

Returns: the IndentCheck attribute

getLevel

public final IndentLevel getLevel()
Get the indentation amount for this handler. For performance reasons, this value is cached. The first time this method is called, the indentation amount is computed and stored. On further calls, the stored value is returned.

Returns: the expected indentation amount

getLevelImpl

protected IndentLevel getLevelImpl()
Compute the indentation amount for this handler.

Returns: the expected indentation amount

getLineStart

protected final int getLineStart(DetailAST aAst)
Get the start of the line for the given expression.

Parameters: aAst the expression to find the start of the line for

Returns: the start of the line for the given expression

getLineStart

protected final int getLineStart(String aLine)
Get the start of the specified line.

Parameters: aLine the specified line number

Returns: the start of the specified line

getMainAst

protected final DetailAST getMainAst()
Accessor for the MainAst attribute.

Returns: the MainAst attribute

getParent

protected final ExpressionHandler getParent()
Accessor for the Parent attribute.

Returns: the Parent attribute

logError

protected final void logError(DetailAST aAst, String aSubtypeName, int aActualLevel)
Log an indentation error.

Parameters: aAst the expression that caused the error aSubtypeName the type of the expression aActualLevel the actual indent level of the expression

logError

protected final void logError(DetailAST aAst, String aSubtypeName, int aActualLevel, IndentLevel aExpectedLevel)
Log an indentation error.

Parameters: aAst the expression that caused the error aSubtypeName the type of the expression aActualLevel the actual indent level of the expression aExpectedLevel the expected indent level of the expression

shouldIncreaseIndent

protected boolean shouldIncreaseIndent()

Returns: true if indentation should be increased after fisrt line in checkLinesIndent() false otherwise

startsLine

protected final boolean startsLine(DetailAST aAst)
Determines if the given expression is at the start of a line.

Parameters: aAst the expression to check

Returns: true if it is, false otherwise

suggestedChildLevel

public IndentLevel suggestedChildLevel(ExpressionHandler aChild)
Indentation level suggested for a child element. Children don't have to respect this, but most do.

Parameters: aChild child AST (so suggestion level can differ based on child type)

Returns: suggested indentation for child