public class TryHandler extends BlockParentHandler
Handler for try blocks.
  • Constructor Details

    • TryHandler

      public TryHandler(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

    • getTryResLparen

      Method to find left parenthesis of try with resources.
      Returns:
      DetailAst left parenthesis of try with resources
    • getTryResRparen

      Method to find right parenthesis of try with resources.
      Returns:
      DetailAst right parenthesis of try with resources
    • getSuggestedChildIndent

      Description copied from class: AbstractExpressionHandler
      Indentation level suggested for a child element. Children don't have to respect this, but most do.
      Overrides:
      getSuggestedChildIndent in class BlockParentHandler
      Parameters:
      child - child AST (so suggestion level can differ based on child type)
      Returns:
      suggested indentation for child
    • checkIndentation

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

      private void checkTryResParen(DetailAST parenAst, String subType)
      Method to check the indentation of left paren or right paren. This method itself checks whether either of these are on start of line. This method takes care of line wrapping strict condition as well.
      Parameters:
      parenAst - lparen or rparen ast to check
      subType - name to be used in log message
    • checkChildIndentation

      private void checkChildIndentation(DetailAST ast, String subType, IndentLevel expectedIdent)
      Method to check indentation of try resources children. It takes into account forceStrictCondition value when logging violations. Example of usage would include checking for try parenthesis and try resources.
      Parameters:
      ast - AST to check.
      subType - String representing child type.
      expectedIdent - Expected indent level.
    • checkTryResources

      private void checkTryResources(DetailAST resourcesSpecAst)
      Checks indentation of resources parameters in try resources.
      Parameters:
      resourcesSpecAst - Resource specification ast
    • isTryBlocksResourceSpecification

      private static boolean isTryBlocksResourceSpecification(AbstractExpressionHandler expression)
      Check if the expression is resource of try block.
      Parameters:
      expression - The expression to check
      Returns:
      if the expression provided is try block's resource specification.