Class LineWrappingHandler
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.checks.indentation.LineWrappingHandler
-
public class LineWrappingHandler extends java.lang.Object
This class checks line-wrapping into definitions and expressions. The line-wrapping indentation should be not less then value of the lineWrappingIndentation parameter.
-
-
Field Summary
Fields Modifier and Type Field Description private IndentationCheck
indentCheck
The current instance ofIndentationCheck
class using this handler.
-
Constructor Summary
Constructors Constructor Description LineWrappingHandler(IndentationCheck instance)
Sets values of class field, finds last node and calculates indentation level.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkAnnotationIndentation(DetailAST atNode, java.util.NavigableMap<java.lang.Integer,DetailAST> firstNodesOnLines, int indentLevel)
Checks line wrapping into annotations.void
checkIndentation(DetailAST firstNode, DetailAST lastNode)
Checks line wrapping into expressions and definitions using property 'lineWrappingIndentation'.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, boolean ignoreFirstLine)
Checks line wrapping into expressions and definitions.private java.util.NavigableMap<java.lang.Integer,DetailAST>
collectFirstNodes(DetailAST firstNode, DetailAST lastNode)
Finds first nodes on line and puts them into Map.private int
expandedTabsColumnNo(DetailAST ast)
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(java.lang.String line)
Get the start of the specified line.private static DetailAST
getNextCurNode(DetailAST curNode)
Returns next curNode node.private static java.lang.Integer
getNextNodeLine(java.util.NavigableMap<java.lang.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 boolean
isEndOfScope(DetailAST lastAnnotationNode, DetailAST node)
Checks line for end of scope.private void
logWarningMessage(DetailAST currentNode, int currentIndent)
Logs warning message if indentation is incorrect.
-
-
-
Field Detail
-
indentCheck
private final IndentationCheck indentCheck
The current instance ofIndentationCheck
class using this handler. This field used to get access to private fields of IndentationCheck instance.
-
-
Constructor Detail
-
LineWrappingHandler
public LineWrappingHandler(IndentationCheck instance)
Sets values of class field, finds last node and calculates indentation level.- Parameters:
instance
- instance of IndentationCheck.
-
-
Method Detail
-
checkIndentation
public void checkIndentation(DetailAST firstNode, DetailAST lastNode)
Checks line wrapping into expressions and definitions using property 'lineWrappingIndentation'.- Parameters:
firstNode
- First node to start examining.lastNode
- Last node to examine inclusively.
-
checkIndentation
public void checkIndentation(DetailAST firstNode, DetailAST lastNode, int indentLevel)
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, boolean 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.
-
getNextNodeLine
private static java.lang.Integer getNextNodeLine(java.util.NavigableMap<java.lang.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.- Parameters:
firstNodesOnLines
- NavigableMap of lines and their first nodes.node
- the node for which to find the next node line- Returns:
- the line number of the next line in the map
-
collectFirstNodes
private java.util.NavigableMap<java.lang.Integer,DetailAST> collectFirstNodes(DetailAST firstNode, DetailAST lastNode)
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.
-
getNextCurNode
private static DetailAST getNextCurNode(DetailAST curNode)
Returns next curNode node.- Parameters:
curNode
- current node.- Returns:
- next curNode node.
-
checkAnnotationIndentation
private void checkAnnotationIndentation(DetailAST atNode, java.util.NavigableMap<java.lang.Integer,DetailAST> firstNodesOnLines, int indentLevel)
Checks line wrapping into annotations.- Parameters:
atNode
- at-clause node.firstNodesOnLines
- map which contains first nodes as values and line numbers as keys.indentLevel
- line wrapping indentation.
-
isEndOfScope
private boolean isEndOfScope(DetailAST lastAnnotationNode, DetailAST node)
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
-
expandedTabsColumnNo
private int expandedTabsColumnNo(DetailAST ast)
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
private int getLineStart(DetailAST ast)
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
private int getLineStart(java.lang.String line)
Get the start of the specified line.- Parameters:
line
- the specified line number- Returns:
- the start of the specified line
-
logWarningMessage
private void logWarningMessage(DetailAST currentNode, int currentIndent)
Logs warning message if indentation is incorrect.- Parameters:
currentNode
- current node which probably invoked an error.currentIndent
- correct indentation.
-
-