Class MethodDefHandler


public class MethodDefHandler extends BlockParentHandler
Handler for method definitions.
  • Constructor Details

    • MethodDefHandler

      public MethodDefHandler(IndentationCheck indentCheck, DetailAST ast, AbstractExpressionHandler parent)
      Construct an instance of this handler with the given indentation check, abstract syntax tree, and parent handler.
      Parameters:
      indentCheck - the indentation check
      ast - the abstract syntax tree
      parent - the parent handler
  • Method Details

    • getTopLevelAst

      protected DetailAST getTopLevelAst()
      Description copied from class: BlockParentHandler
      Get the top level expression being managed by this handler.
      Overrides:
      getTopLevelAst in class BlockParentHandler
      Returns:
      the top level expression
    • checkModifiers

      private void checkModifiers()
      Checks modifiers for method definitions.
    • checkThrows

      private void checkThrows()
      Check the indentation level of the throws clause.
    • getMethodDefLineStart

      private static int getMethodDefLineStart(DetailAST mainAst)
      Gets the start line of the method, excluding any annotations. This is required because the current TokenTypes.METHOD_DEF may not always be the start as seen in #3145.
      Parameters:
      mainAst - The method definition ast.
      Returns:
      The start column position of the method.
    • checkIndentation

      public void checkIndentation()
      Description copied from class: AbstractExpressionHandler
      Check the indentation of the expression we are handling.
      Overrides:
      checkIndentation in class BlockParentHandler
    • shouldCheckLeftParen

      protected boolean shouldCheckLeftParen(DetailAST leftParen)
      Description copied from class: BlockParentHandler
      Determines whether left parenthesis should be checked.
      Overrides:
      shouldCheckLeftParen in class BlockParentHandler
      Parameters:
      leftParen - left parenthesis token
      Returns:
      true if left parenthesis should be checked
    • shouldCheckRightParen

      protected boolean shouldCheckRightParen(DetailAST leftParen, DetailAST rightParen)
      Description copied from class: BlockParentHandler
      Determines whether right parenthesis should be checked.
      Overrides:
      shouldCheckRightParen in class BlockParentHandler
      Parameters:
      leftParen - left parenthesis token
      rightParen - right parenthesis token
      Returns:
      true if right parenthesis should be checked
    • isMethodParenOnItsOwnLineWithMatchingRightParen

      private boolean isMethodParenOnItsOwnLineWithMatchingRightParen(DetailAST leftParen, DetailAST rightParen)
      Checks if method definition parenthesis are wrapped on separate lines and aligned.
      Parameters:
      leftParen - left parenthesis of method definition
      rightParen - right parenthesis of method definition
      Returns:
      true if both parenthesis start their own lines and are aligned
    • getMethodDefParamRightParen

      private static DetailAST getMethodDefParamRightParen(DetailAST methodDefAst)
      Returns right parenthesis of method definition parameter list.
      Parameters:
      methodDefAst - method definition ast node(TokenTypes.LITERAL_IF)
      Returns:
      right parenthesis of method definition parameter list.
    • getHandlerName

      private static String getHandlerName(DetailAST ast)
      Creates a handler name for this class according to ast type.
      Parameters:
      ast - the abstract syntax tree.
      Returns:
      handler name for this class.