java.lang.Object
com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
com.puppycrawl.tools.checkstyle.checks.indentation.NewHandler

Handler for operator new.
  • Field Details

    • LINE_WRAP_NEW_PARENT_TYPES

      private static final int[] LINE_WRAP_NEW_PARENT_TYPES
      Token types that require line wrapping indentation for new keyword.
    • mainAst

      private final DetailAST mainAst
      The AST which is handled by this handler.
  • Constructor Details

    • NewHandler

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

    • checkIndentation

      public void checkIndentation()
      Description copied from class: AbstractExpressionHandler
      Check the indentation of the expression we are handling.
      Specified by:
      checkIndentation in class AbstractExpressionHandler
    • checkNestedNew

      public boolean checkNestedNew(DetailAST expression)
      Check if nested new present.
      Parameters:
      expression - expression
      Returns:
      true if nested new is present.
    • 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 AbstractExpressionHandler
      Parameters:
      child - child AST (so suggestion level can differ based on child type)
      Returns:
      suggested indentation for child
    • getIndentImpl

      Description copied from class: AbstractExpressionHandler
      Compute the indentation amount for this handler.
      Overrides:
      getIndentImpl in class AbstractExpressionHandler
      Returns:
      the expected indentation amount
    • getLineWrappingIndent

      private int getLineWrappingIndent()
      A shortcut for IndentationCheck property.
      Returns:
      value of lineWrappingIndentation property of IndentationCheck
    • shouldIncreaseIndent

      protected boolean shouldIncreaseIndent()
      Description copied from class: AbstractExpressionHandler
      Checks that indentation should be increased after first line in checkLinesIndent().
      Overrides:
      shouldIncreaseIndent in class AbstractExpressionHandler
      Returns:
      true if indentation should be increased after first line in checkLinesIndent() false otherwise
    • doesNewNeedLineWrappingIndent

      private boolean doesNewNeedLineWrappingIndent()
      Checks if the new keyword needs line wrapping indentation. This applies when new is within an assignment, return, throw, or ternary operator (where the ternary is part of an assignment, return, or throw statement).
      Returns:
      true if the new keyword needs line wrapping indentation
    • isParentAssignReturnOrThrow

      private static boolean isParentAssignReturnOrThrow(DetailAST ast)
      Checks if the parent of the given AST is an assignment, return or throw statement.
      Parameters:
      ast - the AST node to check
      Returns:
      true if the parent is ASSIGN, LITERAL_RETURN or LITERAL_THROW
    • getTernaryNestingLevel

      private int getTernaryNestingLevel()
      Counts how many ternary operator levels the new keyword is nested in, where the outermost ternary is part of an assignment, return, or throw.
      Returns:
      the number of ternary nesting levels, or 0 if not in a valid ternary context