Class DetailAST
- java.lang.Object
-
- antlr.BaseAST
-
- antlr.CommonAST
-
- antlr.CommonASTWithHiddenTokens
-
- com.puppycrawl.tools.checkstyle.api.DetailAST
-
- All Implemented Interfaces:
antlr.collections.AST
,java.io.Serializable
public final class DetailAST extends antlr.CommonASTWithHiddenTokens
An extension of the CommonAST that records the line and column number.- See Also:
- ANTLR Website, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.BitSet
branchTokenTypes
All token types in this branch.private int
childCount
Number of children.private int
columnNo
The column number.private int
lineNo
The line number.private static int
NOT_INITIALIZED
Constant to indicate if not calculated the child count.private DetailAST
parent
The parent token.private DetailAST
previousSibling
Previous sibling.private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description DetailAST()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(antlr.collections.AST ast)
void
addNextSibling(DetailAST ast)
Add next sibling.void
addPreviousSibling(DetailAST ast)
Add previous sibling.boolean
branchContains(int type)
Checks if this branch of the parse tree contains a token of the provided type.private void
clearBranchTokenTypes()
Clears branchTokenTypes cache for all parents of the current DetailAST instance, and the child count for the current DetailAST instance.private static void
clearChildCountCache(DetailAST ast)
Clears the child count for the ast instance.private static int
findColumnNo(DetailAST ast)
Finds column number in the first non-comment node.DetailAST
findFirstToken(int type)
Returns the first child token that makes a specified type.private static int
findLineNo(DetailAST ast)
Finds line number in the first non-comment node.private java.util.BitSet
getBranchTokenTypes()
Returns token type with branch.int
getChildCount()
Returns the number of child nodes one level below this node.int
getChildCount(int type)
Returns the number of direct child tokens that have the specified type.int
getColumnNo()
Gets column number.DetailAST
getFirstChild()
DetailAST
getLastChild()
Gets the last child node.int
getLineNo()
Gets line number.DetailAST
getNextSibling()
DetailAST
getParent()
Returns the parent token.DetailAST
getPreviousSibling()
Returns the previous sibling or null if no such sibling exists.void
initialize(antlr.collections.AST ast)
void
initialize(antlr.Token tok)
void
setColumnNo(int columnNo)
Set column number.void
setFirstChild(antlr.collections.AST ast)
void
setLineNo(int lineNo)
Set line number.void
setNextSibling(antlr.collections.AST ast)
private void
setParent(DetailAST parent)
Set the parent token.java.lang.String
toString()
-
Methods inherited from class antlr.BaseAST
decode, encode, equals, equalsList, equalsListPartial, equalsTree, equalsTreePartial, findAll, findAllPartial, getColumn, getLine, getNumberOfChildren, getTokenNames, removeChildren, setVerboseStringConversion, toStringList, toStringTree, xmlSerialize, xmlSerializeNode, xmlSerializeRootClose, xmlSerializeRootOpen
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
NOT_INITIALIZED
private static final int NOT_INITIALIZED
Constant to indicate if not calculated the child count.- See Also:
- Constant Field Values
-
lineNo
private int lineNo
The line number.
-
columnNo
private int columnNo
The column number.
-
childCount
private int childCount
Number of children.
-
parent
private DetailAST parent
The parent token.
-
previousSibling
private DetailAST previousSibling
Previous sibling.
-
branchTokenTypes
private java.util.BitSet branchTokenTypes
All token types in this branch. Token 'x' (where x is an int) is in this branch if branchTokenTypes.get(x) is true.
-
-
Method Detail
-
initialize
public void initialize(antlr.Token tok)
- Specified by:
initialize
in interfaceantlr.collections.AST
- Overrides:
initialize
in classantlr.CommonASTWithHiddenTokens
-
initialize
public void initialize(antlr.collections.AST ast)
- Specified by:
initialize
in interfaceantlr.collections.AST
- Overrides:
initialize
in classantlr.CommonASTWithHiddenTokens
-
setFirstChild
public void setFirstChild(antlr.collections.AST ast)
- Specified by:
setFirstChild
in interfaceantlr.collections.AST
- Overrides:
setFirstChild
in classantlr.BaseAST
-
setNextSibling
public void setNextSibling(antlr.collections.AST ast)
- Specified by:
setNextSibling
in interfaceantlr.collections.AST
- Overrides:
setNextSibling
in classantlr.BaseAST
-
addPreviousSibling
public void addPreviousSibling(DetailAST ast)
Add previous sibling.- Parameters:
ast
- DetailAST object.
-
addNextSibling
public void addNextSibling(DetailAST ast)
Add next sibling.- Parameters:
ast
- DetailAST object.
-
addChild
public void addChild(antlr.collections.AST ast)
- Specified by:
addChild
in interfaceantlr.collections.AST
- Overrides:
addChild
in classantlr.BaseAST
-
getChildCount
public int getChildCount()
Returns the number of child nodes one level below this node. That is is does not recurse down the tree.- Returns:
- the number of child nodes
-
getChildCount
public int getChildCount(int type)
Returns the number of direct child tokens that have the specified type.- Parameters:
type
- the token type to match- Returns:
- the number of matching token
-
setParent
private void setParent(DetailAST parent)
Set the parent token.- Parameters:
parent
- the parent token
-
getParent
public DetailAST getParent()
Returns the parent token.- Returns:
- the parent token
-
getLineNo
public int getLineNo()
Gets line number.- Returns:
- the line number
-
setLineNo
public void setLineNo(int lineNo)
Set line number.- Parameters:
lineNo
- line number.
-
getColumnNo
public int getColumnNo()
Gets column number.- Returns:
- the column number
-
setColumnNo
public void setColumnNo(int columnNo)
Set column number.- Parameters:
columnNo
- column number.
-
getLastChild
public DetailAST getLastChild()
Gets the last child node.- Returns:
- the last child node
-
findColumnNo
private static int findColumnNo(DetailAST ast)
Finds column number in the first non-comment node.- Parameters:
ast
- DetailAST node.- Returns:
- Column number if non-comment node exists, -1 otherwise.
-
findLineNo
private static int findLineNo(DetailAST ast)
Finds line number in the first non-comment node.- Parameters:
ast
- DetailAST node.- Returns:
- Line number if non-comment node exists, -1 otherwise.
-
getBranchTokenTypes
private java.util.BitSet getBranchTokenTypes()
Returns token type with branch.- Returns:
- the token types that occur in the branch as a sorted set.
-
branchContains
public boolean branchContains(int type)
Checks if this branch of the parse tree contains a token of the provided type.- Parameters:
type
- a TokenType- Returns:
- true if and only if this branch (including this node)
contains a token of type
type
.
-
getPreviousSibling
public DetailAST getPreviousSibling()
Returns the previous sibling or null if no such sibling exists.- Returns:
- the previous sibling or null if no such sibling exists.
-
findFirstToken
public DetailAST findFirstToken(int type)
Returns the first child token that makes a specified type.- Parameters:
type
- the token type to match- Returns:
- the matching token, or null if no match
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfaceantlr.collections.AST
- Overrides:
toString
in classantlr.BaseAST
-
getNextSibling
public DetailAST getNextSibling()
- Specified by:
getNextSibling
in interfaceantlr.collections.AST
- Overrides:
getNextSibling
in classantlr.BaseAST
-
getFirstChild
public DetailAST getFirstChild()
- Specified by:
getFirstChild
in interfaceantlr.collections.AST
- Overrides:
getFirstChild
in classantlr.BaseAST
-
clearChildCountCache
private static void clearChildCountCache(DetailAST ast)
Clears the child count for the ast instance.- Parameters:
ast
- The ast to clear.
-
clearBranchTokenTypes
private void clearBranchTokenTypes()
Clears branchTokenTypes cache for all parents of the current DetailAST instance, and the child count for the current DetailAST instance.
-
-