Class MethodDefHandler
java.lang.Object
com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
com.puppycrawl.tools.checkstyle.checks.indentation.BlockParentHandler
com.puppycrawl.tools.checkstyle.checks.indentation.MethodDefHandler
Handler for method definitions.
-
Constructor Summary
ConstructorsConstructorDescriptionMethodDefHandler(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.private voidChecks modifiers for method definitions.private voidCheck the indentation level of the throws clause.private static StringgetHandlerName(DetailAST ast) Creates a handler name for this class according to ast type.private static intgetMethodDefLineStart(DetailAST mainAst) Gets the start line of the method, excluding any annotations.private static DetailASTgetMethodDefParamRightParen(DetailAST methodDefAst) Returns right parenthesis of method definition parameter list.protected DetailASTGet the top level expression being managed by this handler.private booleanisMethodParenOnItsOwnLineWithMatchingRightParen(DetailAST leftParen, DetailAST rightParen) Checks if method definition parenthesis are wrapped on separate lines and aligned.protected booleanshouldCheckLeftParen(DetailAST leftParen) Determines whether left parenthesis should be checked.protected booleanshouldCheckRightParen(DetailAST leftParen, DetailAST rightParen) Determines whether right parenthesis should be checked.Methods inherited from class com.puppycrawl.tools.checkstyle.checks.indentation.BlockParentHandler
canChildrenBeNested, checkTopLevelToken, curlyIndent, getCheckedChildren, getChildrenExpectedIndent, getLeftCurly, getListChild, getNonListChild, getRightCurly, getSuggestedChildIndentMethods inherited from class com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
checkChildren, checkExpressionSubtree, checkLeftParen, checkRightParen, checkWrappingIndentation, checkWrappingIndentation, expandedTabsColumnNo, findSubtreeAst, getBasicOffset, getBraceAdjustment, getFirstAstNode, getFirstLine, getFirstToken, getIndent, getIndentCheck, getIndentImpl, getLineStart, getLineStart, getMainAst, getParent, isOnStartOfLine, logError, logError, shouldCheckIndentationForChild, shouldIncreaseIndent
-
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 checkast- the abstract syntax treeparent- the parent handler
-
-
Method Details
-
getTopLevelAst
Description copied from class:BlockParentHandlerGet the top level expression being managed by this handler.- Overrides:
getTopLevelAstin classBlockParentHandler- Returns:
- the top level expression
-
checkModifiers
Checks modifiers for method definitions. -
checkThrows
Check the indentation level of the throws clause. -
getMethodDefLineStart
Gets the start line of the method, excluding any annotations. This is required because the currentTokenTypes.METHOD_DEFmay not always be the start as seen in #3145.- Parameters:
mainAst- The method definition ast.- Returns:
- The start column position of the method.
-
checkIndentation
Description copied from class:AbstractExpressionHandlerCheck the indentation of the expression we are handling.- Overrides:
checkIndentationin classBlockParentHandler
-
shouldCheckLeftParen
Description copied from class:BlockParentHandlerDetermines whether left parenthesis should be checked.- Overrides:
shouldCheckLeftParenin classBlockParentHandler- Parameters:
leftParen- left parenthesis token- Returns:
- true if left parenthesis should be checked
-
shouldCheckRightParen
Description copied from class:BlockParentHandlerDetermines whether right parenthesis should be checked.- Overrides:
shouldCheckRightParenin classBlockParentHandler- Parameters:
leftParen- left parenthesis tokenrightParen- 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 definitionrightParen- right parenthesis of method definition- Returns:
- true if both parenthesis start their own lines and are aligned
-
getMethodDefParamRightParen
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
Creates a handler name for this class according to ast type.- Parameters:
ast- the abstract syntax tree.- Returns:
- handler name for this class.
-