Package com.puppycrawl.tools.checkstyle
Class DetailAstImpl
java.lang.Object
com.puppycrawl.tools.checkstyle.DetailAstImpl
- All Implemented Interfaces:
DetailAST
The implementation of
DetailAST. This should only be directly used to
create custom AST nodes and in 'JavaAstVisitor.java'.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BitSetAll token types in this branch.private intNumber of children.private intThe column number.private DetailAstImplFirst child of this DetailAST.private List<org.antlr.v4.runtime.Token>All tokens on COMMENTS channel to the right of the current token up to the next token on the DEFAULT_TOKEN_CHANNEL.private List<org.antlr.v4.runtime.Token>All tokens on COMMENTS channel to the left of the current token up to the preceding token on the DEFAULT_TOKEN_CHANNEL.private intThe line number.private DetailAstImplFirst sibling of this DetailAST.private static final intConstant to indicate if not calculated the child count.private DetailAstImplThe parent token.private DetailAstImplPrevious sibling.private StringText of this DetailAST.private intThe type of this DetailAST. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new child to the current AST.voidaddNextSibling(DetailAST ast) Add next sibling, pushes other siblings back.voidAdd previous sibling.booleanbranchContains(int tokenType) Checks if this branch of the parse tree contains a token of the provided type.private voidClears branchTokenTypes cache for all parents of the current DetailAST instance, and the child count for the current DetailAST instance.private static voidClears the child count for the ast instance.private static intfindColumnNo(DetailAST ast) Finds column number in the first non-comment node.findFirstToken(int tokenType) Returns the first child token that makes a specified type.private static intfindLineNo(DetailAST ast) Finds line number in the first non-comment node.private BitSetReturns token type with branch.intReturns the number of child nodes one level below this node.intgetChildCount(int tokenType) Returns the number of direct child tokens that have the specified type.intGets column number.Get the first child of this AST.List<org.antlr.v4.runtime.Token>Get list tokens on COMMENTS channel to the right of the current token up to the next token on the DEFAULT_TOKEN_CHANNEL.List<org.antlr.v4.runtime.Token>Get list of tokens on COMMENTS channel to the left of the current token up to the preceding token on the DEFAULT_TOKEN_CHANNEL.Gets the last child node.intGets line number.Get the next sibling in line after this one.intGet number of children of this AST.Returns the parent token.Returns the previous sibling or null if no such sibling exists.getText()Gets the text of this AST.intgetType()Gets the type of this AST.booleanReturns whether this AST has any children.voidinitialize(int tokenType, String tokenText) Initializes this DetailAstImpl.voidinitialize(org.antlr.v4.runtime.Token token) Initializes this DetailAstImpl.voidRemoves all children of this AST.voidsetColumnNo(int columnNo) Set column number.voidsetFirstChild(DetailAST firstChild) Sets the first child of this AST.voidsetHiddenAfter(List<org.antlr.v4.runtime.Token> hiddenAfter) Sets the hiddenAfter token field.voidsetHiddenBefore(List<org.antlr.v4.runtime.Token> hiddenBefore) Sets the hiddenBefore token field.voidsetLineNo(int lineNo) Set line number.voidsetNextSibling(DetailAST nextSibling) Sets the next sibling of this AST.private voidsetParent(DetailAstImpl parent) Set the parent token.voidSets the text for this DetailAstImpl.voidsetType(int type) Sets the type of this AST.toString()
-
Field Details
-
NOT_INITIALIZED
Constant to indicate if not calculated the child count.- See Also:
-
lineNo
The line number. -
columnNo
The column number. -
childCount
Number of children. -
parent
The parent token. -
previousSibling
Previous sibling. -
firstChild
First child of this DetailAST. -
nextSibling
First sibling of this DetailAST. -
text
Text of this DetailAST. -
type
The type of this DetailAST. -
branchTokenTypes
All token types in this branch. Token 'x' (where x is an int) is in this branch if branchTokenTypes.get(x) is true.
-
-
Constructor Details
-
DetailAstImpl
public DetailAstImpl()
-
-
Method Details
-
initialize
Initializes this DetailAstImpl.- Parameters:
tokenType- the type of this DetailAstImpltokenText- the text of this DetailAstImpl
-
initialize
Initializes this DetailAstImpl.- Parameters:
token- the token to generate this DetailAstImpl from
-
addPreviousSibling
Add previous sibling.- Parameters:
ast- DetailAST object.
-
addNextSibling
Add next sibling, pushes other siblings back.- Parameters:
ast- DetailAST object.
-
addChild
Adds a new child to the current AST.- Parameters:
child- to DetailAST to add as child
-
getChildCount
Description copied from interface:DetailASTReturns the number of child nodes one level below this node. That is, does not recurse down the tree.- Specified by:
getChildCountin interfaceDetailAST- Returns:
- the number of child nodes
-
getChildCount
Description copied from interface:DetailASTReturns the number of direct child tokens that have the specified type.- Specified by:
getChildCountin interfaceDetailAST- Parameters:
tokenType- the token type to match- Returns:
- the number of matching token
-
setParent
Set the parent token.- Parameters:
parent- the parent token
-
getParent
Description copied from interface:DetailASTReturns the parent token. -
getText
Description copied from interface:DetailASTGets the text of this AST. -
setText
Sets the text for this DetailAstImpl.- Parameters:
text- the text field of this DetailAstImpl
-
getType
Description copied from interface:DetailASTGets the type of this AST. -
setType
Sets the type of this AST.- Parameters:
type- the token type of this DetailAstImpl
-
getLineNo
Description copied from interface:DetailASTGets line number. -
setLineNo
Set line number.- Parameters:
lineNo- line number.
-
getColumnNo
Description copied from interface:DetailASTGets column number.- Specified by:
getColumnNoin interfaceDetailAST- Returns:
- the column number
-
setColumnNo
Set column number.- Parameters:
columnNo- column number.
-
getLastChild
Description copied from interface:DetailASTGets the last child node.- Specified by:
getLastChildin interfaceDetailAST- Returns:
- the last child node
-
findColumnNo
Finds column number in the first non-comment node.- Parameters:
ast- DetailAST node.- Returns:
- Column number if non-comment node exists, -1 otherwise.
-
findLineNo
Finds line number in the first non-comment node.- Parameters:
ast- DetailAST node.- Returns:
- Line number if non-comment node exists, -1 otherwise.
-
getBranchTokenTypes
Returns token type with branch.- Returns:
- the token types that occur in the branch as a sorted set.
-
branchContains
Description copied from interface:DetailASTChecks if this branch of the parse tree contains a token of the provided type.- Specified by:
branchContainsin interfaceDetailAST- Parameters:
tokenType- a TokenType- Returns:
- true if and only if this branch (including this node)
contains a token of type
type.
-
getPreviousSibling
Description copied from interface:DetailASTReturns the previous sibling or null if no such sibling exists.- Specified by:
getPreviousSiblingin interfaceDetailAST- Returns:
- the previous sibling or null if no such sibling exists.
-
findFirstToken
Description copied from interface:DetailASTReturns the first child token that makes a specified type.- Specified by:
findFirstTokenin interfaceDetailAST- Parameters:
tokenType- the token type to match- Returns:
- the matching token, or null if no match
-
toString
-
getNextSibling
Description copied from interface:DetailASTGet the next sibling in line after this one.- Specified by:
getNextSiblingin interfaceDetailAST- Returns:
- the next sibling or null if none.
-
getFirstChild
Description copied from interface:DetailASTGet the first child of this AST.- Specified by:
getFirstChildin interfaceDetailAST- Returns:
- the first child or null if none.
-
getNumberOfChildren
Description copied from interface:DetailASTGet number of children of this AST.- Specified by:
getNumberOfChildrenin interfaceDetailAST- Returns:
- the number of children.
-
hasChildren
Description copied from interface:DetailASTReturns whether this AST has any children.- Specified by:
hasChildrenin interfaceDetailAST- Returns:
trueif this AST has any children.
-
clearChildCountCache
Clears the child count for the ast instance.- Parameters:
ast- The ast to clear.
-
clearBranchTokenTypes
Clears branchTokenTypes cache for all parents of the current DetailAST instance, and the child count for the current DetailAST instance. -
setNextSibling
Sets the next sibling of this AST.- Parameters:
nextSibling- the DetailAST to set as sibling
-
setFirstChild
Sets the first child of this AST.- Parameters:
firstChild- the DetailAST to set as first child
-
removeChildren
Removes all children of this AST. -
getHiddenBefore
Get list of tokens on COMMENTS channel to the left of the current token up to the preceding token on the DEFAULT_TOKEN_CHANNEL.- Returns:
- list of comment tokens
-
getHiddenAfter
Get list tokens on COMMENTS channel to the right of the current token up to the next token on the DEFAULT_TOKEN_CHANNEL.- Returns:
- list of comment tokens
-
setHiddenBefore
Sets the hiddenBefore token field.- Parameters:
hiddenBefore- comment token preceding this DetailAstImpl
-
setHiddenAfter
Sets the hiddenAfter token field.- Parameters:
hiddenAfter- comment token following this DetailAstImpl
-