Class LineWrappingHandler
java.lang.Object
com.puppycrawl.tools.checkstyle.checks.indentation.LineWrappingHandler
This class checks line-wrapping into definitions and expressions. The
line-wrapping indentation should be not less than value of the
lineWrappingIndentation parameter.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum to be used for test if first line's indentation should be checked or not. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]
The list of ignored token types for being checked by lineWrapping indentation insidecheckIndentation()
as these tokens are checked for lineWrapping inside their dedicated handlers.private final IndentationCheck
The current instance ofIndentationCheck
class using this handler. -
Constructor Summary
ConstructorsConstructorDescriptionLineWrappingHandler
(IndentationCheck instance) Sets values of class field, finds last node and calculates indentation level. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkAnnotationIndentation
(DetailAST atNode, NavigableMap<Integer, DetailAST> firstNodesOnLines, int indentLevel) Checks line wrapping into annotations.void
checkForAnnotationIndentation
(NavigableMap<Integer, DetailAST> firstNodesOnLines, int indentLevel) Checks for annotation indentation.static boolean
Checks whether the method lparen starts from a new line or not.static boolean
Checks whether parameter node has any child or not.void
checkIndentation
(DetailAST firstNode, DetailAST lastNode) Checks line wrapping into expressions and definitions using property 'lineWrappingIndentation'.private void
checkIndentation
(DetailAST firstNode, DetailAST lastNode, int indentLevel) Checks line wrapping into expressions and definitions.void
checkIndentation
(DetailAST firstNode, DetailAST lastNode, int indentLevel, int startIndent, LineWrappingHandler.LineWrappingOptions ignoreFirstLine) Checks line wrapping into expressions and definitions.private NavigableMap<Integer,
DetailAST> collectFirstNodes
(DetailAST firstNode, DetailAST lastNode) Finds first nodes on line and puts them into Map.private int
Get the column number for the start of a given expression, expanding tabs out into spaces in the process.private int
getLineStart
(DetailAST ast) Get the start of the line for the given expression.private int
getLineStart
(String line) Get the start of the specified line.private static DetailAST
getNextCurNode
(DetailAST curNode) Returns next curNode node.private static Integer
getNextNodeLine
(NavigableMap<Integer, DetailAST> firstNodesOnLines, DetailAST node) Gets the next node line from the firstNodesOnLines map unless there is no next line, in which case, it returns the last line.private static boolean
isEndOfScope
(DetailAST lastAnnotationNode, DetailAST node) Checks line for end of scope.private static boolean
isParentContainsTokenType
(DetailAST node, int type) Checks that some parent of given node contains given token type.private void
logWarningMessage
(DetailAST currentNode, int currentIndent) Logs warning message if indentation is incorrect.private boolean
Checks whether indentation ofTEXT_BLOCK_LITERAL_END
needs to be checked.
-
Field Details
-
IGNORED_LIST
The list of ignored token types for being checked by lineWrapping indentation insidecheckIndentation()
as these tokens are checked for lineWrapping inside their dedicated handlers. -
indentCheck
The current instance ofIndentationCheck
class using this handler. This field used to get access to private fields of IndentationCheck instance.
-
-
Constructor Details
-
LineWrappingHandler
Sets values of class field, finds last node and calculates indentation level.- Parameters:
instance
- instance of IndentationCheck.
-
-
Method Details
-
checkIndentation
Checks line wrapping into expressions and definitions using property 'lineWrappingIndentation'.- Parameters:
firstNode
- First node to start examining.lastNode
- Last node to examine inclusively.
-
checkIndentation
Checks line wrapping into expressions and definitions.- Parameters:
firstNode
- First node to start examining.lastNode
- Last node to examine inclusively.indentLevel
- Indentation all wrapped lines should use.
-
checkIndentation
public void checkIndentation(DetailAST firstNode, DetailAST lastNode, int indentLevel, int startIndent, LineWrappingHandler.LineWrappingOptions ignoreFirstLine) Checks line wrapping into expressions and definitions.- Parameters:
firstNode
- First node to start examining.lastNode
- Last node to examine inclusively.indentLevel
- Indentation all wrapped lines should use.startIndent
- Indentation first line before wrapped lines used.ignoreFirstLine
- Test if first line's indentation should be checked or not.
-
checkForNullParameterChild
Checks whether parameter node has any child or not.- Parameters:
node
- the node for which to check.- Returns:
- true if parameter has no child.
-
checkForMethodLparenNewLine
Checks whether the method lparen starts from a new line or not.- Parameters:
node
- the node for which to check.- Returns:
- true if method lparen starts from a new line.
-
collectFirstNodes
Finds first nodes on line and puts them into Map.- Parameters:
firstNode
- First node to start examining.lastNode
- Last node to examine inclusively.- Returns:
- NavigableMap which contains lines numbers as a key and first nodes on lines as a values.
-
shouldProcessTextBlockLiteral
Checks whether indentation ofTEXT_BLOCK_LITERAL_END
needs to be checked. Yes if it is first on start of the line.- Parameters:
node
- the node- Returns:
- true if node is line-starting node.
-
getNextCurNode
Returns next curNode node.- Parameters:
curNode
- current node.- Returns:
- next curNode node.
-
isEndOfScope
Checks line for end of scope. Handles occurrences of close braces and close parenthesis on the same line.- Parameters:
lastAnnotationNode
- the last node of the annotationnode
- the node indicating where to begin checking- Returns:
- true if all the nodes up to the last annotation node are end of scope nodes false otherwise
-
isParentContainsTokenType
Checks that some parent of given node contains given token type.- Parameters:
node
- node to checktype
- type to look for- Returns:
- true if there is a parent of given type
-
expandedTabsColumnNo
Get the column number for the start of a given expression, expanding tabs out into spaces in the process.- Parameters:
ast
- the expression to find the start of- Returns:
- the column number for the start of the expression
-
getLineStart
Get the start of the line for the given expression.- Parameters:
ast
- the expression to find the start of the line for- Returns:
- the start of the line for the given expression
-
getLineStart
Get the start of the specified line.- Parameters:
line
- the specified line number- Returns:
- the start of the specified line
-
logWarningMessage
Logs warning message if indentation is incorrect.- Parameters:
currentNode
- current node which probably invoked a violation.currentIndent
- correct indentation.
-