## com.puppycrawl.tools.checkstyle.checks.indentation
Class BlockParentHandler

    java.lang.Object
      com.puppycrawl.tools.checkstyle.checks.indentation.ExpressionHandler
          com.puppycrawl.tools.checkstyle.checks.indentation.BlockParentHandler

Direct Known Subclasses:
  ArrayInitHandler, AssignHandler, CatchHandler, ClassDefHandler, DoWhileHandler, ElseHandler, FinallyHandler, ForHandler, IfHandler, MethodDefHandler, ObjectBlockHandler, SlistHandler, StaticInitHandler, SwitchHandler, TryHandler, WhileHandler

    public class BlockParentHandler

extends ExpressionHandler

Handler for parents of blocks ('if', 'else', 'while', etc).

The "block" handler classes use a common superclass BlockParentHandler, employing the Template Method pattern.

- template method to get the lcurly
- template method to get the rcurly
- if curlys aren't present, then template method to get expressions is called
- now all the repetitous code which checks for BOL, if curlys are on same line, etc. can be collapsed into the superclass

Author:
  jrichard

Constructor Summary
`BlockParentHandler(IndentationCheck aIndentCheck, String aName, DetailAST aAst, ExpressionHandler aParent)` Construct an instance of this handler with the given indentation check, name, abstract syntax tree, and parent handler.

Method Summary
`void` `checkIndentation()` Check the indentation of the expression we are handling.
`protected void` `checkLCurly()` Check the indentation of the left curly brace.
`protected void` `checkRCurly()` Check the indentation of the right curly brace.
`protected void` `checkToplevelToken()` Check the indent of the top level token.
`protected boolean` `childrenMayNest()` Determines if child elements within the expression may be nested.
`protected int[]` `getCheckedChildren()` Returns array of token types which should be checked among childrens.
`protected IndentLevel` `getChildrenExpectedLevel()`
`protected DetailAST` `getLCurly()` Get the left curly brace portion of the expression we are handling.
`protected DetailAST` `getListChild()` Get the child element representing the list of statements.
`protected DetailAST` `getLParen()` Get the left parenthesis portion of the expression we are handling.
`protected DetailAST` `getNonlistChild()` Get the child element that is not a list of statements.
`protected DetailAST` `getRCurly()` Get the right curly brace portion of the expression we are handling.
`protected DetailAST` `getRParen()` Get the right parenthesis portion of the expression we are handling.
`protected DetailAST` `getToplevelAST()` Get the top level expression being managed by this handler.
`protected boolean` `hasCurlys()` Determines if this block expression has curly braces.
`protected boolean` `rcurlyMustStart()` Determines if the right curly brace must be at the start of the line.
`IndentLevel` `suggestedChildLevel(ExpressionHandler aChild)` Indentation level suggested for a child element.
`protected boolean` `toplevelMustStartLine()` Determines if the top level token must start the line.

Methods inherited from class com.puppycrawl.tools.checkstyle.checks.indentation.ExpressionHandler
`checkChildren, checkExpressionSubtree, checkLinesIndent, checkLParen, checkModifiers, checkRParen, expandedTabsColumnNo, findSubtreeLines, getBasicOffset, getBraceAdjustement, getFirstLine, getIndentCheck, getLevel, getLevelImpl, getLineStart, getLineStart, getMainAst, getParent, logError, logError, shouldIncreaseIndent, startsLine`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### BlockParentHandler

    public BlockParentHandler(IndentationCheck aIndentCheck,
                              String aName,
                              DetailAST aAst,
                              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
    `aName` - the name of the handler
    `aAst` - the abstract syntax tree
    `aParent` - the parent handler

Method Detail

### getCheckedChildren

    protected int[] getCheckedChildren()

  Returns array of token types which should be checked among childrens.

  Returns:
    array of token types to check.

### getToplevelAST

    protected DetailAST getToplevelAST()

  Get the top level expression being managed by this handler.

  Returns:
    the top level expression

### checkToplevelToken

    protected void checkToplevelToken()

  Check the indent of the top level token.

### toplevelMustStartLine

    protected boolean toplevelMustStartLine()

  Determines if the top level token must start the line.

  Returns:
    true

### hasCurlys

    protected boolean hasCurlys()

  Determines if this block expression has curly braces.

  Returns:
    true if curly braces are present, false otherwise

### getLCurly

    protected DetailAST getLCurly()

  Get the left curly brace portion of the expression we are handling.

  Returns:
    the left curly brace expression

### getRCurly

    protected DetailAST getRCurly()

  Get the right curly brace portion of the expression we are handling.

  Returns:
    the right curly brace expression

### checkLCurly

    protected void checkLCurly()

  Check the indentation of the left curly brace.

### rcurlyMustStart

    protected boolean rcurlyMustStart()

  Determines if the right curly brace must be at the start of the line.

  Returns:
    true

### childrenMayNest

    protected boolean childrenMayNest()

  Determines if child elements within the expression may be nested.

  Returns:
    false

### checkRCurly

    protected void checkRCurly()

  Check the indentation of the right curly brace.

### getNonlistChild

    protected DetailAST getNonlistChild()

  Get the child element that is not a list of statements.

  Returns:
    the non-list child element

### getListChild

    protected DetailAST getListChild()

  Get the child element representing the list of statements.

  Returns:
    the statement list child

### getRParen

    protected DetailAST getRParen()

  Get the right parenthesis portion of the expression we are handling.

  Returns:
    the right parenthis expression

### getLParen

    protected DetailAST getLParen()

  Get the left parenthesis portion of the expression we are handling.

  Returns:
    the left parenthis expression

### checkIndentation

    public void checkIndentation()

  Description copied from class: `ExpressionHandler`
  Check the indentation of the expression we are handling.

  Specified by:
    `checkIndentation` in class `ExpressionHandler`

### getChildrenExpectedLevel

    protected IndentLevel getChildrenExpectedLevel()

  Returns:
    indentation level expected for children

### suggestedChildLevel

    public IndentLevel suggestedChildLevel(ExpressionHandler aChild)

  Description copied from class: `ExpressionHandler`
  Indentation level suggested for a child element. Children don't have to respect this, but most do.

  Overrides:
    `suggestedChildLevel` in class `ExpressionHandler`
  Parameters:
    `aChild` - child AST (so suggestion level can differ based on child type)
  Returns:
    suggested indentation for child

Copyright © 2001-2011. All Rights Reserved.