Class NewHandler
java.lang.Object
com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
com.puppycrawl.tools.checkstyle.checks.indentation.NewHandler
Handler for operator new.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]Token types that require line wrapping indentation for new keyword.private final DetailASTThe AST which is handled by this handler. -
Constructor Summary
ConstructorsConstructorDescriptionNewHandler(IndentationCheck indentCheck, DetailAST ast, AbstractExpressionHandler parent) Construct an instance of this handler with the given indentation check, abstract syntax tree, and parent handler. -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck the indentation of the expression we are handling.booleancheckNestedNew(DetailAST expression) Check if nestednewpresent.private booleanChecks if the new keyword needs line wrapping indentation.protected IndentLevelCompute the indentation amount for this handler.private intA shortcut forIndentationCheckproperty.Indentation level suggested for a child element.private intCounts how many ternary operator levels the new keyword is nested in, where the outermost ternary is part of an assignment, return, or throw.private static booleanChecks if the parent of the given AST is an assignment, return or throw statement.protected booleanChecks that indentation should be increased after first line in checkLinesIndent().Methods inherited from class com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
checkChildren, checkExpressionSubtree, checkLeftParen, checkModifiers, checkRightParen, checkWrappingIndentation, checkWrappingIndentation, expandedTabsColumnNo, findSubtreeAst, getBasicOffset, getBraceAdjustment, getFirstAstNode, getFirstLine, getFirstToken, getIndent, getIndentCheck, getLineStart, getLineStart, getMainAst, getParent, isOnStartOfLine, logError, logError
-
Field Details
-
LINE_WRAP_NEW_PARENT_TYPES
Token types that require line wrapping indentation for new keyword. -
mainAst
The AST which is handled by this handler.
-
-
Constructor Details
-
NewHandler
Construct an instance of this handler with the given indentation check, abstract syntax tree, and parent handler.- Parameters:
indentCheck- the indentation checkast- the abstract syntax treeparent- the parent handler
-
-
Method Details
-
checkIndentation
Description copied from class:AbstractExpressionHandlerCheck the indentation of the expression we are handling.- Specified by:
checkIndentationin classAbstractExpressionHandler
-
checkNestedNew
Check if nestednewpresent.- Parameters:
expression- expression- Returns:
- true if nested new is present.
-
getSuggestedChildIndent
Description copied from class:AbstractExpressionHandlerIndentation level suggested for a child element. Children don't have to respect this, but most do.- Overrides:
getSuggestedChildIndentin classAbstractExpressionHandler- Parameters:
child- child AST (so suggestion level can differ based on child type)- Returns:
- suggested indentation for child
-
getIndentImpl
Description copied from class:AbstractExpressionHandlerCompute the indentation amount for this handler.- Overrides:
getIndentImplin classAbstractExpressionHandler- Returns:
- the expected indentation amount
-
getLineWrappingIndent
A shortcut forIndentationCheckproperty.- Returns:
- value of lineWrappingIndentation property
of
IndentationCheck
-
shouldIncreaseIndent
Description copied from class:AbstractExpressionHandlerChecks that indentation should be increased after first line in checkLinesIndent().- Overrides:
shouldIncreaseIndentin classAbstractExpressionHandler- Returns:
- true if indentation should be increased after first line in checkLinesIndent() false otherwise
-
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
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
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
-