com.puppycrawl.tools.checkstyle.checks.indentation

Class ExpressionHandler

Known Direct Subclasses:
BlockParentHandler, CaseHandler, ImportHandler, LabelHandler, MethodCallHandler, PackageDefHandler, PrimordialHandler

public abstract class ExpressionHandler
extends java.lang.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 void
checkChildren(DetailAST aParent, int[] aTokenTypes, IndentLevel aStartLevel, boolean aFirstLineMatches, boolean aAllowNesting)
Check the indent level of the children of the specified parent expression.
protected void
checkExpressionSubtree(DetailAST aTree, IndentLevel aLevel, boolean aFirstLineMatches, boolean aAllowNesting)
Check the indentation level for an expression subtree.
void
checkIndentation()
Check the indentation of the expression we are handling.
protected void
checkLinesIndent(int aStartLine, int aEndLine, IndentLevel aIndentLevel)
Check the indentation of consecutive lines for the expression we are handling.
protected void
checkModifiers()
Check the indentation level of modifiers.
protected int
expandedTabsColumnNo(DetailAST aAst)
Get the column number for the start of a given expression, expanding tabs out into spaces in the process.
protected void
findSubtreeLines(LineSet aLines, DetailAST aTree, boolean aAllowNesting)
Find the set of lines for a given subtree.
protected int
getBasicOffset()
A shortcut for IndentationCheck property.
protected int
getBraceAdjustement()
A shortcut for IndentationCheck property.
protected int
getFirstLine(int aStartLine, DetailAST aTree)
Get the first line for a given expression.
protected IndentationCheck
getIndentCheck()
Accessor for the IndentCheck attribute.
IndentLevel
getLevel()
Get the indentation amount for this handler.
protected IndentLevel
getLevelImpl()
Compute the indentation amount for this handler.
protected int
getLineStart(String aLine)
Get the start of the specified line.
protected int
getLineStart(DetailAST aAst)
Get the start of the line for the given expression.
protected DetailAST
getMainAst()
Accessor for the MainAst attribute.
protected ExpressionHandler
getParent()
Accessor for the Parent attribute.
protected void
logError(DetailAST aAst, String aSubtypeName, int aActualLevel)
Log an indentation error.
protected void
logError(DetailAST aAst, String aSubtypeName, int aActualLevel, IndentLevel aExpectedLevel)
Log an indentation error.
protected boolean
shouldIncreaseIndent()
protected boolean
startsLine(DetailAST aAst)
Determines if the given expression is at the start of a line.
IndentLevel
suggestedChildLevel(ExpressionHandler aChild)
Indentation level suggested for a child element.

Constructor Details

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 Details

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 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


checkModifiers

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


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(String aLine)
Get the start of the specified line.

Parameters:
aLine - the specified line number

Returns:
the start of the specified line


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


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