public abstract class AnnotatedAst extends antlr.CommonAST implements Aast
setHidden(boolean) flag can optionally be honored during
the walk, to bypass child nodes marked as hidden. See
iterator(int,AstWalkListener,boolean).
| Modifier and Type | Field and Description |
|---|---|
private static java.util.Map<java.lang.String,java.lang.String> |
ANNO_LOWER |
private java.util.IdentityHashMap<java.lang.String,java.lang.Object> |
annotations
Map of annotation objects, indexed by name
|
private int |
column
Source file column number associated with this AST
|
private boolean |
hidden
Hidden mode which can be used to modify iterator based walking.
|
private java.lang.Long |
id
Unique, persistent identifier
|
private int |
line
Source file line number associated with this AST
|
private TreeLocal |
local
Tree-specific data (data that is shared by all nodes of a tree.
|
private static ConversionStatus |
LOG
Logger
|
private Aast |
parent
Parent node to this node
|
private java.lang.Object[] |
runtimeAnnotations
Storage for runtime annotation - an array of length
Aast.RUNTIME_ANNOTATION_COUNT. |
private AnnotatedAst |
tail
Right-most child node, if any
|
RUNTIME_ANNOTATION_COUNT, RUNTIME_CLASS, RUNTIME_CONSTRUCTOR, RUNTIME_METHOD, RUNTIME_VALUE| Constructor and Description |
|---|
AnnotatedAst()
Default constructor.
|
AnnotatedAst(antlr.Token token)
Constructor which accepts and wrappers token.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
absolutePath(java.lang.Object[] path)
Compares this node's complete path from the root node (down to and including the current node) with the
specified path.
|
boolean |
absolutePath(java.lang.String path)
Deprecated.
|
void |
addChild(antlr.collections.AST node)
Add a child to the list of this node's children.
|
boolean |
ancestor(int level,
int type)
Searches the AST's ancestors for an exact token type match.
|
boolean |
ancestor(int level,
int[] types)
Searches the AST's ancestors for a token type that matches any of a
given list of token types.
|
boolean |
ancestor(int level,
int lower,
int upper)
Searches the AST's ancestors for a token type that matches a given
range of token types (inclusively).
|
int |
annotationCount(java.lang.String key,
java.lang.Object value)
Returns the number of annotation objects of an array annotation that are
equal to the specified
Object. |
java.util.Iterator<java.lang.String> |
annotationKeys()
Get an iterator on the keys for all annotations (if any) stored in this
AST.
|
int |
annotationSize(java.lang.String key)
Returns the size of an array annotation as indexed by an arbitrary key.
|
void |
brainwash(java.lang.String filename)
Clear all IDs of an AST and register it under a new filename.
|
void |
brainwash(java.lang.String filename,
boolean shadow)
Clear all IDs of an AST and register it under a new filename.
|
void |
clearAnnotations()
Removes ALL annotations from this AST.
|
void |
clearIds()
Clears (sets to
null) the unique ID of this node and all
descendant nodes using recursion. |
boolean |
compareWith(Aast other)
Compare subtree starting from
this node as a root and
compare it with given subtree. |
boolean |
compareWith(Aast other,
boolean ignoreCase)
Compare subtree starting from
this node as a root and
compare it with given subtree. |
private AnnotatedAst |
createNode(antlr.Token token,
Aast parent)
Create a new AST node of the same sub-class as the current node and
initialize it using the given token.
|
private void |
createShadowNodes(java.lang.Long fileId)
Read the original token out of the
original-token annotation and create
shadow nodes from the hidden before and after tokens if they exist. |
boolean |
descendant(int level,
int type)
Searches the AST's descendants for an exact token type match.
|
boolean |
descendant(int level,
int[] types)
Searches the AST's descendants for a token type that matches any of a
given list of token types.
|
boolean |
descendant(int level,
int[] types,
java.lang.String key,
java.lang.Object match,
java.lang.Integer index)
Searches the AST's descendants for a token type that matches any of a given list of token
types and for each found, matches the given value for an annotation.
|
boolean |
descendant(int level,
int lower,
int upper)
Searches the AST's descendants for a token type that matches a given
range of token types (inclusively).
|
boolean |
descendant(int level,
int lower,
int upper,
java.lang.String key,
java.lang.Object match,
java.lang.Integer index)
Searches the AST's descendants for a token type that matches a given range of token types
(inclusively), and for each found, matches the given value for an annotation.
|
boolean |
downPath(int tok1)
Determines if this node's path downward matches the specified path.
|
boolean |
downPath(int tok1,
int tok2)
Determines if this node's path downward matches the specified path.
|
boolean |
downPath(int tok1,
int tok2,
int tok3)
Determines if this node's path downward matches the specified path.
|
boolean |
downPath(int tok1,
int tok2,
int tok3,
int tok4)
Determines if this node's path downward matches the specified path.
|
boolean |
downPath(java.lang.Object... path)
Determines if this node's path downward matches the specified path.
|
boolean |
downPath(java.lang.String path)
Deprecated.
Use downPath(Integer... path) instead.
|
private void |
driveFixups(Aast child)
Kickoff the fixup process on a specific child to set IDs and ensure
that all parent linkages are correct.
|
java.lang.String |
dumpSimpleTree()
Create a human readable text concise representation of the tree rooted at this AST.
|
java.lang.String |
dumpTree()
Create a human readable text representation of the tree rooted at this
AST.
|
java.lang.String |
dumpTree(boolean annotations)
Create a human readable text representation of the tree rooted at this AST.
|
Aast |
duplicate()
Creates a deep copy of the original, including all descendant ASTs.
|
Aast |
duplicate(java.util.Map<java.lang.Long,Aast> idMap)
Creates a deep copy of the original, including all descendant ASTs.
|
Aast |
duplicateFresh()
Creates a deep copy of the original, including all descendant ASTs.
|
Aast |
duplicateFresh(java.util.Map<java.lang.Long,Aast> idMap)
Creates a deep copy of the original, including all descendant ASTs.
|
private void |
extractTokenData(antlr.Token token)
Extract line number, column number from the input token and store this information as
member data.
|
private Aast |
farthest(boolean right)
Search the sub-tree rooted at this node to return the AST node that exists farthest to the
left or right (in line/column).
|
void |
fixupParent(Aast parent)
Fixup the parent references for this tree.
|
void |
fixups(Aast parent,
java.lang.Long fileId)
Assigns parent nodes throughout the AST hierarchy of which this AST is
the root.
|
void |
fixups(Aast parent,
java.lang.Long fileId,
boolean shadow)
Assigns parent nodes throughout the AST hierarchy of which this AST is
the root.
|
Aast |
getAncestor(int level)
Get the ancestor node at the specified number of levels of ancestry,
if it exists.
|
Aast |
getAncestor(int level,
int type)
Get the first ancestor node of a specified type found in a walk up to
the maximum specified number of levels of ancestry, if such a node
exists.
|
Aast |
getAncestor(int level,
int type,
java.lang.String key,
java.lang.Object value)
Get the first ancestor node of the specified type which also has a particular annotation
with the specified value.
|
Aast |
getAncestor(int level,
java.util.List<java.lang.Integer> types)
Get the first ancestor node of the specified types found in a walk up to
the maximum specified number of levels of ancestry, if such a node
exists.
|
java.lang.Object |
getAnnotation(java.lang.String key)
Retrieve an annotation.
|
java.lang.Object |
getAnnotation(java.lang.String key,
int index)
Retrieve an element in an array annotation using the specified key as
a unique identifier and an index to specify the location in the array
from which to read the element.
|
private static java.lang.String |
getAnnotationKey(java.lang.String anno)
Get the lowercase annotation key from the
ANNO_LOWER cache. |
java.util.List<java.lang.Object> |
getAnnotationList(java.lang.String key)
Retrieve an unmodifiable list view of an array annotation.
|
Aast |
getChildAt(int index)
Search the immediate children for the one at the specified index.
|
int |
getColumn()
Get the source code column number which designates where in the source
code file the token wrappered by this node was found.
|
int |
getDepth()
Get the level of nesting of this AST from the root AST, where
0 indicates the root, and a positive number indicates
generations from the root. |
java.lang.String |
getDescriptiveTokenText()
Returns a descriptive string for the current node.
|
java.lang.String |
getFilename()
Get source code filename associated with the current node.
|
private Aast |
getFirstChild(boolean honorHidden)
Returns the first child (hidden or not) if the
honorHidden
flag is false, or the first non-hidden child if the
honorHidden flag is true. |
java.lang.Long |
getId()
Retrieve this AST's unique, persistent identifier.
|
Aast |
getImmediateChild(java.util.Collection<java.lang.Integer> types,
Aast start)
Search the immediate children for one that matches any token type in
the specified Collection of types.
|
Aast |
getImmediateChild(int type,
Aast start)
Search the immediate children for one that matches a specific token
type.
|
java.util.List<Aast> |
getImmediateChildren(int type)
Get immediate child nodes of this AST that match a
specific token type.
|
int |
getIndexPos()
Returns the index position of this instance in the array of children
of its parent.
|
Aast |
getLastImmediateChild(int type)
Search the immediate children for last child that matches a specific
token type.
|
Aast |
getLeftAdjacent()
Search the tree to return the AST node that exists nearest on the left (in line/column).
|
Aast |
getLeftmost()
Search the sub-tree rooted at this node to return the AST node that exists farthest to the
left (in line/column).
|
ShadowNode |
getLeftmostShadow()
Access a shadow node that exists farthest to the left of the current node.
|
ShadowNode |
getLeftShadow()
Access a shadow node that exists to the left of the current node.
|
Aast |
getLeftShadowNode()
Access the AST of a shadow node that exists to the left of the current node.
|
int |
getLine()
Get the source code line number which designates where in the source
code file the token wrappered by this node was found.
|
TreeLocal |
getLocal()
Access the tree-local data directly.
|
private Aast |
getNextSibling(boolean honorHidden)
Returns the next sibling (hidden or not) if the
honorHidden
flag is false, or the next non-hidden sibling if the
honorHidden flag is true. |
int |
getNumChildren()
Get the total number of all descendants of this AST.
|
int |
getNumImmediateChildren()
Get the number of immediate child nodes of this AST.
|
int |
getNumImmediateChildren(int type)
Get the number of immediate child nodes of this AST that match a
specific token type.
|
int |
getNumLeftSiblings()
Returns the number of siblings to this node's left (before this node
in a tree walk).
|
int |
getNumRightSiblings()
Returns the number of siblings to this node's right (after this node
in a tree walk).
|
Aast |
getParent()
Get this Aast's parent node, if any.
|
private Aast[] |
getParentChain(Aast node)
Get chain of parent nodes starting from root to this node.
|
java.lang.String |
getPath()
Return a string representing the path of this AST from the root AST,
in terms of the token type of each element from the root to this AST.
|
private java.lang.String |
getPath(int max)
Return a string representing the path of this AST from an ancestor (possibly the root) AST,
in terms of the token type of each element from the ancestor to this AST.
|
Aast |
getPrevSibling()
Returns the sibling to the left of this node in the tree or
null if this instance is the first child of its parent. |
Aast |
getRightAdjacent()
Search the tree to return the AST node that exists nearest on the right (in line/column).
|
Aast |
getRightmost()
Search the sub-tree rooted at this node to return the AST node that exists farthest to the
right (in line/column).
|
ShadowNode |
getRightmostShadow()
Access a shadow node that exists farthest to the right of the current node.
|
ShadowNode |
getRightShadow()
Access a shadow node that exists to the right of the current node.
|
Aast |
getRightShadowNode()
Access the AST of a shadow node that exists to the right of the current node.
|
java.lang.Object |
getRuntimeAnnotation(int key)
Get the runtime annotation with the specified key.
|
java.util.Iterator<ShadowNode> |
getShadowNodeList()
Access the list of all shadow nodes.
|
abstract java.lang.String |
getSymbolicTokenType()
Returns the symbolic representation of this AST's token type.
|
void |
graft(Aast child)
Grafts a new child subtree onto this AST.
|
void |
graftAt(Aast child,
int index)
Grafts a new child subtree onto this AST at a specific 0-based child
index.
|
Aast |
graftCopyTo(Aast parent,
int[] validTokens)
Grafts a copy of this AST node onto the specified parent AST.
|
Aast |
graftCopyTo(Aast parent,
int[] validTokens,
boolean preserve)
Grafts a copy of this AST node onto the specified parent AST.
|
void |
initialize(antlr.collections.AST ast)
Initialize this node with the specified AST.
|
void |
initialize(antlr.Token token)
Initialize this node with the specified token.
|
void |
intern()
Walk the tree formed by this node and all of its descendants, interning all strings stored
in the AST's text and annotation values which are
String objects. |
boolean |
isAncestorOf(int level,
Aast other)
Report whether this node is an ancestor of the given node.
|
boolean |
isAnnotation(java.lang.String key)
Determines if an annotation exists of any
String,
Double, Long, Boolean or
List value, indexed by an arbitrary key. |
boolean |
isArtificial()
Reports on a node that was not generated by parsing text, but was created for some
structural purpose by the parser or by post-processing code.
|
boolean |
isHidden()
Get this AST's hidden status.
|
boolean |
isLeaf()
Indicate whether this AST node represents a leaf node in the tree (a
node with no children).
|
boolean |
isRoot()
Indicate whether this AST node represents the root of its hierarchy.
|
boolean |
isRuntimeAnnotation(int key)
Check if the runtime annotation with the specified key is set.
|
java.util.Iterator<Aast> |
iterator()
Return an iterator to walk this AST recursively in a depth-first
traversal.
|
java.util.Iterator<Aast> |
iterator(int maxLevels,
AstWalkListener listener)
Return an iterator to walk this AST recursively in a depth-first
traversal.
|
java.util.Iterator<Aast> |
iterator(int maxLevels,
AstWalkListener listener,
boolean honorHidden)
Return an iterator to walk this AST recursively in a depth-first
traversal.
|
abstract java.lang.String |
lookupTokenName(int type)
Translates an integer value of a token type into the associated
human readable text representation.
|
abstract int |
lookupTokenType(java.lang.String tokenName)
Translates a text representation of a token type into the
actual integer value.
|
boolean |
matchAnnotation(java.lang.String key,
java.lang.Object match,
java.lang.Integer index)
Indicate whether this AST has an annotation which matches the specified conditions.
|
void |
move(Aast parent,
int index)
Move the node from one location to another.
|
private Aast |
nearest(boolean right)
Search the tree to return the AST node that exists nearest to the left or right (in
line/column).
|
Aast |
nearestEnclosing(Aast other)
Find and return the nearest ancestor of the current instance which also
encloses the node passed as a parameter.
|
protected abstract AnnotatedAst |
newInstance()
Create a new instance of this AST implementation.
|
void |
putAnnotation(java.lang.String key,
java.lang.Boolean annotation)
Store a boolean annotation using the specified key as a unique
identifier.
|
void |
putAnnotation(java.lang.String key,
java.lang.Boolean annotation,
int index)
Store a boolean element in an array annotation using the
specified key as a unique identifier and an index to specify the
location in which to insert.
|
void |
putAnnotation(java.lang.String key,
java.lang.Double annotation)
Store a floating point numeric annotation using the specified key as a
unique identifier.
|
void |
putAnnotation(java.lang.String key,
java.lang.Double annotation,
int index)
Store a floating point numeric element in an array annotation using the
specified key as a unique identifier and an index to specify the
location in which to insert.
|
void |
putAnnotation(java.lang.String key,
java.util.List<java.lang.Object> annotation)
Store a list of annotations at once using the specified key as a unique
identifier.
|
void |
putAnnotation(java.lang.String key,
java.lang.Long annotation)
Store an integral numeric annotation using the specified key as a
unique identifier.
|
void |
putAnnotation(java.lang.String key,
java.lang.Long annotation,
int index)
Store an integral numeric element in an array annotation using the
specified key as a unique identifier and an index to specify the
location in which to insert.
|
void |
putAnnotation(java.lang.String key,
java.lang.String annotation)
Store a text annotation using the specified key as a unique identifier.
|
void |
putAnnotation(java.lang.String key,
java.lang.String annotation,
int index)
Store a text element in an array annotation using the specified key as
a unique identifier and an index to specify the location in which to
insert.
|
private void |
putAnnotationImpl(java.lang.String key,
java.lang.Object annotation)
Stores an annotation object under a unique key, creating the map of
annotations first, if necessary.
|
private boolean |
putAnnotationImpl(java.lang.String key,
java.lang.Object annotation,
int index)
Stores an annotation object in an array annotation under a unique key, creating both the
array itself and the map of annotations first, if necessary.
|
void |
putAnnotationObject(java.lang.String key,
java.lang.Object annotation)
Store any object as annotation for this node.
|
boolean |
relativePath(int tok1)
Determines if this node's path from the root ends with the specified path.
|
boolean |
relativePath(int tok1,
int tok2)
Determines if this node's path from the root ends with the specified path.
|
boolean |
relativePath(int tok1,
int tok2,
int tok3)
Determines if this node's path from the root ends with the specified path.
|
boolean |
relativePath(int tok1,
int tok2,
int tok3,
int tok4)
Determines if this node's path from the root ends with the specified path.
|
boolean |
relativePath(java.lang.Object... path)
Determines if this node's path from the root ends with the specified path.
|
boolean |
relativePath(java.lang.String path)
Deprecated.
Use relativePath(Integer... path) instead.
|
void |
remove()
Remove this AST (and the entire sub-tree rooted at this node) from its
parent's collection of children.
|
java.lang.Object |
removeAnnotation(java.lang.String key)
Remove a specific annotation from this AST.
|
java.lang.Object |
removeAnnotation(java.lang.String key,
int index)
Remove a specific element from the array annotation in this AST.
|
void |
removeChildren()
Remove all child nodes.
|
private boolean |
searchDown(java.lang.Object[] list,
int index)
Worker to recursively search down the descendant tree to match the passed-in list of token types.
|
private boolean |
searchDown(java.lang.String[] list,
int index)
Worker to recursively search down the descendant tree to match the
passed-in list of token names.
|
private static boolean |
searchUp(AnnotatedAst node,
java.lang.Object[] path,
int k,
boolean absolute)
Worker to compare the given source path (from root to a given node) to the expected path to the target
and return the comparison results.
|
private boolean |
searchUp(java.lang.String source,
java.lang.String target)
Worker to compare the given source path (from root to a given node) to
the expected path to the target and return the comparison results.
|
void |
setColumn(int column)
Set the source file column number for this node.
|
void |
setFirstChild(antlr.collections.AST node)
Set the first child node of this AST.
|
void |
setHidden(boolean hide)
Set this AST's hidden status.
|
boolean |
setId(java.lang.Long id)
Set this AST's unique, persistent identifier.
|
void |
setLine(int line)
Set the source file line number for this node.
|
void |
setLocal(TreeLocal local)
Set the tree-local data directly.
|
void |
setNextSibling(antlr.collections.AST node)
Set the next sibling to the right of this AST, replacing any such node already present
though fixups are not performed.
|
void |
setParent(Aast parent)
Set this Aast's parent node.
|
void |
setRuntimeAnnotation(int key,
java.lang.Object value)
Set the runtime annotation with the specified key.
|
boolean |
sibling(long type)
Test whether any of this node's siblings has the given token type.
|
java.lang.String |
toString()
Create a string representation of this AST.
|
java.lang.String |
toStringVerbose()
Create a verbose string representation of this AST.
|
boolean |
upPath(int tok1)
Determines if this node's path upward matches the specified path.
|
boolean |
upPath(int tok1,
int tok2)
Determines if this node's path upward matches the specified path.
|
boolean |
upPath(int tok1,
int tok2,
int tok3)
Determines if this node's path upward matches the specified path.
|
boolean |
upPath(int tok1,
int tok2,
int tok3,
int tok4)
Determines if this node's path upward matches the specified path.
|
boolean |
upPath(java.lang.Object... path)
Determines if this node's path upward matches the specified path.
|
boolean |
upPath(java.lang.String path)
Deprecated.
Use upPath(Integer... path) instead.
|
decode, encode, equals, equalsList, equalsListPartial, equalsTree, equalsTreePartial, findAll, findAllPartial, getFirstChild, getNextSibling, getNumberOfChildren, getTokenNames, setVerboseStringConversion, toStringList, toStringTree, xmlSerialize, xmlSerializeNode, xmlSerializeRootClose, xmlSerializeRootOpenclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetImmediateChildprivate static final ConversionStatus LOG
private java.lang.Long id
private int line
private int column
private Aast parent
private AnnotatedAst tail
private boolean hidden
private java.util.IdentityHashMap<java.lang.String,java.lang.Object> annotations
private TreeLocal local
private java.lang.Object[] runtimeAnnotations
Aast.RUNTIME_ANNOTATION_COUNT.private static java.util.Map<java.lang.String,java.lang.String> ANNO_LOWER
public AnnotatedAst()
public AnnotatedAst(antlr.Token token)
token - Token upon which this node is based.private static java.lang.String getAnnotationKey(java.lang.String anno)
ANNO_LOWER cache.public abstract int lookupTokenType(java.lang.String tokenName)
lookupTokenType in interface AasttokenName - The text representation of the token type.public abstract java.lang.String lookupTokenName(int type)
lookupTokenName in interface Aasttype - The integer token type.null if
no match was found.protected abstract AnnotatedAst newInstance()
public void removeChildren()
removeChildren in class antlr.BaseASTpublic void addChild(antlr.collections.AST node)
addChild in interface antlr.collections.ASTaddChild in class antlr.BaseASTnode - Child node to add to the end of the list of child nodes. If null, the
method does nothing. If not null, this object must be of type
AnnotatedAst.public void setFirstChild(antlr.collections.AST node)
setFirstChild in interface antlr.collections.ASTsetFirstChild in class antlr.BaseASTnode - Child node to set as the first child of this AST. If null, any existing
list of child nodes is removed. If not null, this object must be of type
AnnotatedAst.public void setNextSibling(antlr.collections.AST node)
setNextSibling in interface antlr.collections.ASTsetNextSibling in class antlr.BaseASTnode - Child node to set as the next sibling. If null, any existing sibling
nodes to the right of this node are removed. If not null, this object must
be of type AnnotatedAst.public void setLine(int line)
public void setColumn(int column)
public Aast graftCopyTo(Aast parent, int[] validTokens) throws AstException
validTokens), all
child nodes of the copy which do not match a valid token type
are removed from the copy node, before it is grafted onto the parent.
All necessary parent and ID fixups are performed on the copy to
integrate it with its new parent tree.
The line and column numbers will be preserved in the duplicated tree.
graftCopyTo in interface Aastparent - AST node which will become the direct parent of the grafted
copy of this node.validTokens - Optional array of valid token types. If not null,
only those children of the copy node which match a valid token
type are allowed to remain. All other child nodes are removed
from the copy.AstException - if any error occurs registering the grafted node with the AST
registry.public Aast graftCopyTo(Aast parent, int[] validTokens, boolean preserve) throws AstException
validTokens), all
child nodes of the copy which do not match a valid token type
are removed from the copy node, before it is grafted onto the parent.
All necessary parent and ID fixups are performed on the copy to
integrate it with its new parent tree.graftCopyTo in interface Aastparent - AST node which will become the direct parent of the grafted
copy of this node.validTokens - Optional array of valid token types. If not null,
only those children of the copy node which match a valid token
type are allowed to remain. All other child nodes are removed
from the copy.preserve - true to preserve line and column information in
the duplicated tree.AstException - if any error occurs registering the grafted node with the AST
registry.public void graft(Aast child) throws AstException
graft in interface Aastchild - AST subtree to add as a child of this node.AstException - if any error occurs registering the grafted node with the AST
registry.public void graftAt(Aast child, int index) throws AstException
graftAt in interface Aastchild - AST subtree to add as a child of this node.index - 0 to insert as the first child, -1 to insert as the last
child or a 0-based index to specify an exact child index
at which to insert the new child. All current children at
that index or at a greater index, are moved right. If the
index is greater than the current number of children, the
new child will be added at the end.AstException - if any error occurs registering the grafted node with the AST
registry.public Aast duplicate()
public Aast duplicate(java.util.Map<java.lang.Long,Aast> idMap)
public Aast duplicateFresh()
All unique IDs of this new sub-tree are cleared before this method
returns (see clearIds()).
duplicateFresh in interface Aastnull if there is any
exception during the copy.public Aast duplicateFresh(java.util.Map<java.lang.Long,Aast> idMap)
All unique IDs of this new sub-tree are cleared before this method
returns (see clearIds()).
duplicateFresh in interface AastidMap - Map of IDs to ASTs. May be null.null if there is any
exception during the copy.public void clearIds()
null) the unique ID of this node and all
descendant nodes using recursion. Warning: this is very dangerous so
you have better know what you are doing!public void brainwash(java.lang.String filename)
throws AstException
This would be done in order to safely save a copy AST under a different filename than the source AST. It is necessary in order to avoid having two ASTs registered to the same filename and ID in the AST registry.
No shadow nodes will be created using this version of the method. All hidden tokens will be dropped.
brainwash in interface Aastfilename - New filename under which the AST is registered.AstException - if any error occurs registering AST or applying fixups.public void brainwash(java.lang.String filename,
boolean shadow)
throws AstException
This would be done in order to safely save a copy AST under a different filename than the source AST. It is necessary in order to avoid having two ASTs registered to the same filename and ID in the AST registry.
filename - New filename under which the AST is registered.shadow - true to create shadow nodes from hidden tokens.
false to drop hidden tokens without creating any
shadow nodes.AstException - if any error occurs registering AST or applying fixups.public java.lang.Long getId()
null return from this method generally indicates an
invalid AST.public boolean isRoot()
null
parent. Note that this will create false positives for an AST which
has not yet had its initial "fix-up" performed.public boolean isLeaf()
public boolean setId(java.lang.Long id)
Normally, it would be better to set this value during construction. However, we do not have control over the construction process when this AST is instantiated by ANTLR during parsing, so it is done early in post-processing instead.
public java.lang.String getPath()
BLOCK/STATEMENT/KW_IF/
represents the following path:
ROOT [type=BLOCK]
|
NODE A [type=STATEMENT]
|
NODE B [type=KW_IF]
The string uniquely identifies the path from this node back to the root,
but is not necessarily unique when traversed from the root to this node.public int getDepth()
0 indicates the root, and a positive number indicates
generations from the root.public int getNumImmediateChildren()
getNumImmediateChildren in interface Aastpublic java.util.List<Aast> getImmediateChildren(int type)
type - The token type of the child nodes to search for.public int getNumImmediateChildren(int type)
getNumImmediateChildren in interface Aasttype - The token type of the child nodes to search for.public int getNumChildren()
getNumChildren in interface Aastpublic void initialize(antlr.collections.AST ast)
ast.initialize in interface antlr.collections.ASTinitialize in class antlr.CommonASTast - AST upon which this node is based. Expected to be an instance
of Aast.public void initialize(antlr.Token token)
token for later use in
line number and column queries.initialize in interface antlr.collections.ASTinitialize in class antlr.CommonASTtoken - Token upon which this node is based.public Aast getParent()
public void setParent(Aast parent)
public boolean isHidden()
public void setHidden(boolean hide)
public int getIndexPos()
getIndexPos in interface Aastpublic Aast getPrevSibling()
null if this instance is the first child of its parent.
This method is much slower than its counterpart
getNextSibling since each node does not maintain a
reference back to the previous node. Thus, the parent node must
be involved and this extra processing slows the resulting
implementation.
getPrevSibling in interface Aastnull if this node is the
first child (or has no parent).public Aast getAncestor(int level)
getAncestor in interface Aastlevel - Number of generations up the tree to walk to obtain the
ancestor. Set to -1 to obtain the tree root,
0 is the current node, 1 is the
parent, 2 is the 'grandparent' and so forth.null
if no such node exists (if level specified is
greater than depth of the tree).public Aast getAncestor(int level, int type)
getAncestor in interface Aastlevel - Maximum number of generations up the tree to search for an
ancestor. Set to -1 to search up to the tree
root, 0 for the current node, 1 for
the parent, 2 for the 'grandparent' and so forth.type - The token type of the ancestor to find.null
if no such node exists (if level specified is
greater than depth of the tree).public Aast getAncestor(int level, java.util.List<java.lang.Integer> types)
getAncestor in interface Aastlevel - Maximum number of generations up the tree to search for an
ancestor. Set to -1 to search up to the tree
root, 0 for the current node, 1 for
the parent, 2 for the 'grandparent' and so forth.types - The token types of the ancestor to find.null
if no such node exists (if level specified is
greater than depth of the tree).public Aast getAncestor(int level, int type, java.lang.String key, java.lang.Object value)
null value is provided, then the existence alone of
an annotation with the specified key is considered a match. The search walks up the tree
from this node to the maximum specified number of levels of ancestry.getAncestor in interface Aastlevel - Number of generations up the tree to walk to obtain the ancestor. Set to -1
to go up to the tree root, 0 only the current node, 1 is the
parent, 2 is the 'grandparent' and so forth.type - The token type of the ancestor to find. Use 0 as wildcard to match all
nodes. In this case the key/value combination will be used for filtering.key - Annotation key to match.value - Annotation value to match. null to match any node which has an annotation
with the specified key, regardless of its value.null if no such node exists
(if level specified is greater than depth of the tree).public boolean ancestor(int level,
int type)
ancestor in interface Aastlevel - Maximum number of generations up the tree to search for an
ancestor. Set to -1 to search up to the tree
root, 0 for the current node, 1 for
the parent, 2 for the 'grandparent' and so forth.type - Token type to be matched.true if type was found as a
ancestor's token type within level
generations, else false.public boolean ancestor(int level,
int lower,
int upper)
ancestor in interface Aastlevel - Maximum number of generations up the tree to search for an
ancestor. Set to -1 to search up to the tree
root, 0 for the current node, 1 for
the parent, 2 for the 'grandparent' and so forth.lower - Lower boundary of the token type range.upper - Upper boundary of the token type range.true if a ancestor's token type was found to
match a range of types within level generations,
else false.public boolean ancestor(int level,
int[] types)
ancestor in interface Aastlevel - Maximum number of generations up the tree to search for an
ancestor. Set to -1 to search up to the tree
root, 1 to search up to the parent, 2
2 to search up to the 'grandparent', and so forth.types - The list of token types for which to search.true if a ancestor's token type was found to
match any of the given list of types within level
generations, else false.public boolean descendant(int level,
int type)
descendant in interface Aastlevel - Number of generations to search before abandoning the test.
Set to 0 to search exhaustively.type - Token type to be matched.true if type was found as a
descendant's token type within level
generations, else false.public boolean descendant(int level,
int lower,
int upper)
descendant in interface Aastlevel - Number of generations to search before abandoning the test.
Set to 0 to search exhaustively.lower - Lower boundary of the token type range.upper - Upper boundary of the token type range.true if a descendant's token type was found to
match a range of types within level generations,
else false.public boolean descendant(int level,
int lower,
int upper,
java.lang.String key,
java.lang.Object match,
java.lang.Integer index)
descendant in interface Aastlevel - Number of generations to search before abandoning the test. Set to 0 to
search exhaustively.lower - Lower boundary of the token type range.upper - Upper boundary of the token type range.key - Key of the annotation to match. If null, only the token types are used as
match criteria.match - Value of the annotation to match. Ignored if key is null. Must be
the same data type as the annotation being searched.index - Zero-based index of the annotation, if the annotation is part of a list.
Set to -1 to test all elements of an annotation list.
Set to null for a scalar annotation.true if a descendant's token type was found to match a range of types
and an optional annotation was found to match within level generations,
else false.public boolean descendant(int level,
int[] types)
descendant in interface Aastlevel - Number of generations to search before abandoning the test.
Set to 0 to search exhaustively.types - The list of token types for which to search.true if a descendant's token type was found to
match any of the given list of types within level
generations, else false.public boolean descendant(int level,
int[] types,
java.lang.String key,
java.lang.Object match,
java.lang.Integer index)
descendant in interface Aastlevel - Number of generations to search before abandoning the test.
Set to 0 to search exhaustively.types - The list of token types for which to search.key - Key of the annotation to match. If null, only the token types are used as
match criteria.match - Value of the annotation to match. Ignored if key is null. Must be
the same data type as the annotation being searched.index - Zero-based index of the annotation, if the annotation is part of a list.
Set to -1 to test all elements of an annotation list.
Set to null for a scalar annotation.true if a descendant's token type was found to match any of the given
list of types and an optional annotation was matched within level
generations, else false.public boolean matchAnnotation(java.lang.String key,
java.lang.Object match,
java.lang.Integer index)
The match succeeds if an annotation exists with the given key and match
value. If index is not null, the annotation must exist in an annotation
list and the annotation element at the given index must match the given match
value.
The match fails under the following conditions without raising an error:
key;key, but it does not match the given
value;index is a positive value that is out-of-bounds for the annotation list;index is not null and the annotation is scalar.matchAnnotation in interface Aastkey - The key under which to check for an annotation. May not be null.match - An object to match as the annotation's value. Must be the same data type as the
annotation, such that a comparison using equals will determine whether
the annotation matches. May not be null.index - Non-negative, zero-based index of the annotation, if it is part of a list.
Set to null for a scalar annotation.
Set to -1 to check all elements of a list for a match.true if a matching annotation exists, else false.public boolean sibling(long type)
public int getNumLeftSiblings()
getIndexPos().getNumLeftSiblings in interface Aastpublic int getNumRightSiblings()
getNumRightSiblings in interface Aastpublic boolean isAncestorOf(int level,
Aast other)
isAncestorOf in interface Aastlevel - The number of generations to search before abandoning the test.
Set to 0 to search exhaustively.other - The node whose ancestry will be tested.true if this node is an ancestor of
other, else false. Returns
false if this == other .@Deprecated public boolean absolutePath(java.lang.String path)
absolutePath in interface Aastpath - Root-to-current path, formatted as described in
getPath().true if specified path matches this node's path
exactly, else false.public boolean absolutePath(java.lang.Object[] path)
absolutePath in interface Aastpath - Root-to-current path, as an array of integers representing the types of the ancestor's nodes.true if specified path matches this node's path exactly, else false.@Deprecated public boolean relativePath(java.lang.String path)
This node's type IS included in this path, which is different from the
upPath(java.lang.String) which compares paths upward starting at the parent
node.
relativePath in interface Aastpath - Partial path from this node up to an arbitrary number of
parent nodes, formatted as described in getPath().true if specified path matches the end of this
node's path exactly, else false.public boolean relativePath(java.lang.Object... path)
This node's type IS included in this path, which is different from the upPath(java.lang.String) which compares
paths upward starting at the parent node.
relativePath in interface Aastpath - Partial path from this node up to an arbitrary number of parent nodes.true if specified path matches the end of this node's path exactly.public boolean relativePath(int tok1)
This node's type IS included in this path, which is different from the upPath(java.lang.String) which compares
paths upward starting at the parent node.
relativePath in interface Aasttok1 - The first token for this path match.true if specified path matches the end of this node's path exactly.public boolean relativePath(int tok1,
int tok2)
This node's type IS included in this path, which is different from the upPath(java.lang.String) which compares
paths upward starting at the parent node.
relativePath in interface Aasttok1 - The first token for this path match.tok2 - The second token for this path match.true if specified path matches the end of this node's path exactly.public boolean relativePath(int tok1,
int tok2,
int tok3)
This node's type IS included in this path, which is different from the upPath(java.lang.String) which compares
paths upward starting at the parent node.
relativePath in interface Aasttok1 - The first token for this path match.tok2 - The second token for this path match.tok3 - The third token for this path match.true if specified path matches the end of this node's path exactly.public boolean relativePath(int tok1,
int tok2,
int tok3,
int tok4)
This node's type IS included in this path, which is different from the upPath(java.lang.String) which compares
paths upward starting at the parent node.
relativePath in interface Aasttok1 - The first token for this path match.tok2 - The second token for this path match.tok3 - The third token for this path match.tok4 - The fourth token for this path match.true if specified path matches the end of this node's path exactly.@Deprecated public boolean upPath(java.lang.String path)
The type of the current node is NOT included in the up path. This
is the only difference between this method and relativePath(java.lang.String).
public boolean upPath(java.lang.Object... path)
The type of the current node is NOT included in the up path. This is the only difference between this
method and relativePath(java.lang.String).
public boolean upPath(int tok1)
The type of the current node is NOT included in the up path. This is the only difference between this
method and relativePath(java.lang.String).
public boolean upPath(int tok1,
int tok2)
The type of the current node is NOT included in the up path. This is the only difference between this
method and relativePath(java.lang.String).
public boolean upPath(int tok1,
int tok2,
int tok3)
The type of the current node is NOT included in the up path. This is the only difference between this
method and relativePath(java.lang.String).
public boolean upPath(int tok1,
int tok2,
int tok3,
int tok4)
The type of the current node is NOT included in the up path. This is the only difference between this
method and relativePath(java.lang.String).
upPath in interface Aasttok1 - The first token for this path match.tok2 - The second token for this path match.tok3 - The third token for this path match.tok4 - The fourth token for this path match.true if specified path exactly matches the upward path from this node's parent.@Deprecated public boolean downPath(java.lang.String path)
true.
The format of the 'segments' of the down path starts with the immediate child's type and each subsequent segment must be the type of the next child down in the hierarchy. The type of the current node is NOT included in the down path.
public boolean downPath(java.lang.Object... path)
true.
The list of the 'segments' of the down path starts with the immediate child's type and each subsequent segment must be the type of the next child down in the hierarchy. The type of the current node is NOT included in the down path.
public boolean downPath(int tok1)
true.
The list of the 'segments' of the down path starts with the immediate child's type and each subsequent segment must be the type of the next child down in the hierarchy. The type of the current node is NOT included in the down path.
public boolean downPath(int tok1,
int tok2)
true.
The list of the 'segments' of the down path starts with the immediate child's type and each subsequent segment must be the type of the next child down in the hierarchy. The type of the current node is NOT included in the down path.
public boolean downPath(int tok1,
int tok2,
int tok3)
true.
The list of the 'segments' of the down path starts with the immediate child's type and each subsequent segment must be the type of the next child down in the hierarchy. The type of the current node is NOT included in the down path.
public boolean downPath(int tok1,
int tok2,
int tok3,
int tok4)
true.
The list of the 'segments' of the down path starts with the immediate child's type and each subsequent segment must be the type of the next child down in the hierarchy. The type of the current node is NOT included in the down path.
downPath in interface Aasttok1 - The first token for this path match.tok2 - The second token for this path match.tok3 - The third token for this path match.tok4 - The fourth token for this path match.true if specified path exactly matches the downward path from this node.public Aast nearestEnclosing(Aast other)
nearestEnclosing in interface Aastother - Another reference node in the same tree.null if
the two AST nodes are not in the same tree. If the two
references are identical (they are the same node), the
parent node will be returned (even if this is
null due to the given node being the tree
root). Finally, if one node encloses the other, the
enclosing node will be returned.public Aast getChildAt(int index)
null.getChildAt in interface Aastindex - The 0-based index at which to search.null if no
such index exists.public Aast getImmediateChild(int type, Aast start)
null, then the search will start with the first
child.getImmediateChild in interface Aasttype - The token type of the child for which to search.start - The child from which to start the search or null
if the search is to start with the first child.null if no match was found.public Aast getImmediateChild(java.util.Collection<java.lang.Integer> types, Aast start)
types collection.
An optional starting child AST can be provided which allows a search
to be made for matches subsequent to the first, if the start AST is
null, then the search will start with the first child.getImmediateChild in interface Aasttypes - Collection of token types of the child for which to search.start - The child from which to start the search or null
if the search is to start with the first child.null if no match was found.public Aast getLastImmediateChild(int type)
getLastImmediateChild in interface Aasttype - The token type of the child for which to search.null
if no match was found.public void remove()
This method has no effect if invoked on the root node of an AST.
public void move(Aast parent, int index) throws AstException
Aast nodes must be the same
between the current node and the parent node, otherwise the results
will be undefined.
If the given parent node is null and the current parent
node of this instance is null, this method returns
immediately since there is nothing to do.
move in interface Aastparent - The parent node which is the target of the move operation or
null if the move is only affecting the index
position of this node (a move of the child to a different
index in the same parent).index - 0 to insert as the first child, -1 to insert as the last
child or a 0-based index to specify an exact child index
at which to insert the new child. All current nodes at
that index or at a greater index, are moved right. If the
index is greater than the current number of nodes, the node
will be added at the end.AstException - if any error occurs registering the grafted node with the AST
registry.public java.lang.String getFilename()
AstManager by this AST's
ID.getFilename in interface Aastnull if the ID is null or invalid.public boolean isArtificial()
isArtificial in interface Aasttrue if this is an artificial node.public int getLine()
0 for an artificially manufactured AST (i.e., one
not generated by a parser).getLine in interface antlr.collections.ASTgetLine in class antlr.BaseAST0 for an artificial AST.getColumn()public int getColumn()
0 for an artificially manufactured AST (i.e., one
not generated by a parser).getColumn in interface antlr.collections.ASTgetColumn in class antlr.BaseAST0 for an artificial AST.getLine()public abstract java.lang.String getSymbolicTokenType()
getSymbolicTokenType in interface Aastpublic java.lang.String getDescriptiveTokenText()
getDescriptiveTokenText in interface Aastpublic java.util.Iterator<Aast> iterator()
This iterator will not support any "non-visiting" events (descent, ascent and next-child). In addition, all nodes will be returned, regardless of hidden status. EXCEPTION: shadow nodes are NOT included in any tree walks and will NOT be returned by this iterator.
public java.util.Iterator<Aast> iterator(int maxLevels, AstWalkListener listener)
The iterator will walk at most to a node depth of maxLevels
relative to this node. A maxLevels value of 0
indicates that the full tree beneath this node should be walked, down
to every leaf, regardless of its depth.
If a listener is specified, it will be notified when the
tree walk transitions between nesting levels. The notifications occur
during processing of the iterator's next method. In each
case (whether the transition represents a descent to a lower tree level
or an ascent to a higher tree level), the parent of the parent/child
link being traversed will be sent with the notification. No more than
a single descent notification will ever be sent during a single
invocation of the iterator's next method. However,
multiple ascent notifications may be sent, since the tree walk may
proceed directly from a deeply nested node to the next sibling of a
distant ancestor node. In such a case, one call to the listener's
AstWalkListener.ascent(com.goldencode.ast.Aast) method will be made for each upward
step from child to parent, until an ancestor with an unvisited sibling
is found, or the walk ends.
This iterator will return all nodes in the tree, regardless of hidden status. EXCEPTION: shadow nodes are NOT included in any tree walks and will NOT be returned by this iterator.
iterator in interface AastmaxLevels - Maximum number of levels or generations to visit relative to
the root defined by ast. If the tree contains
more levels than maxLevels, the levels beyond a
relative depth of maxLevels will be ignored. Set
to 0 to disable this restriction. Set to
1 for immediate children only, etc.listener - An optional listener which is notified of significant events
during the tree walk, such as descents to lower nesting levels,
moves between children (next-child events) and ascents back up
to higher nesting levels. This may be null if
these "non-visiting" events are not needed.public java.util.Iterator<Aast> iterator(int maxLevels, AstWalkListener listener, boolean honorHidden)
The iterator will walk at most to a node depth of maxLevels
relative to this node. A maxLevels value of 0
indicates that the full tree beneath this node should be walked, down
to every leaf, regardless of its depth.
If a listener is specified, it will be notified when the
tree walk transitions between nesting levels. The notifications occur
during processing of the iterator's next method. In each
case (whether the transition represents a descent to a lower tree level
or an ascent to a higher tree level), the parent of the parent/child
link being traversed will be sent with the notification. No more than
a single descent notification will ever be sent during a single
invocation of the iterator's next method. However,
multiple ascent notifications may be sent, since the tree walk may
proceed directly from a deeply nested node to the next sibling of a
distant ancestor node. In such a case, one call to the listener's
AstWalkListener.ascent(com.goldencode.ast.Aast) method will be made for each upward
step from child to parent, until an ancestor with an unvisited sibling
is found, or the walk ends.
Optionally, the returned iterator can omit nodes in which the hidden
status is enabled (see isHidden() and setHidden(boolean)).
Please note that if the root node (the instance upon which this method
is called) is set as hidden, this setting will
not be honored. The hidden mode is only
honored on child nodes that have this mode set.
EXCEPTION: shadow nodes are NOT included in any tree walks and will NOT be returned by this iterator.
iterator in interface AastmaxLevels - Maximum number of levels or generations to visit relative to
the root defined by ast. If the tree contains
more levels than maxLevels, the levels beyond a
relative depth of maxLevels will be ignored. Set
to 0 to disable this restriction. Set to
1 for immediate children only, etc.listener - An optional listener which is notified of significant events
during the tree walk, such as descents to lower nesting levels,
moves between children (next-child events) and ascents back up
to higher nesting levels. This may be null if
these "non-visiting" events are not needed.honorHidden - If true, the hidden attribute of
the node will be honored. This means that the node will not
appear in the iterator nor will any "non-visiting" events be
triggered for such nodes.public boolean isAnnotation(java.lang.String key)
String,
Double, Long, Boolean or
List value, indexed by an arbitrary key.isAnnotation in interface Aastkey - Key under which the annotation is stored.true if an annotation exists mapped by that key.public int annotationSize(java.lang.String key)
annotationSize in interface Aastkey - Key under which the annotation is stored.public int annotationCount(java.lang.String key,
java.lang.Object value)
Object.annotationCount in interface Aastkey - Key under which the annotation is stored.value - Object to compare with.public java.lang.Object getAnnotation(java.lang.String key)
String,
Double, Long, or Boolean value,
indexed by an arbitrary key. Note that it is possible to obtain the
entire array if the annotation is an array type. This would be a
List of objects of the above mentioned types.getAnnotation in interface Aastkey - Key under which the annotation is stored.null if none exists.public java.lang.Object getAnnotation(java.lang.String key,
int index)
String, Double, Long, or
Boolean value.getAnnotation in interface Aastkey - Key under which the annotation is stored.index - The index of -1 indicates the last element of the array.
Otherwise this is the explicit zero-based index at which to
find the annotation.null if the annotation
doesn't exist, if the annotation is not an array or if no
element exists at the given index.public java.util.List<java.lang.Object> getAnnotationList(java.lang.String key)
getAnnotationList in interface Aastkey - Key under which the annotation is stored.null if no such
annotation exists.public void putAnnotation(java.lang.String key,
java.lang.String annotation)
This is just a thin wrapper to ensure annotation type safety, since
annotations are stored in a Map as Objects.
putAnnotation in interface Aastkey - Key under which to store the annotation.annotation - Arbitrary text.public void putAnnotation(java.lang.String key,
java.lang.String annotation,
int index)
putAnnotation in interface Aastkey - Key under which to store the annotation.annotation - Arbitrary text.index - The index of -1 indicates an addition to the end of the array.
Otherwise this is the explicit zero-based index at which to
add the annotation.public void putAnnotation(java.lang.String key,
java.lang.Double annotation)
This is just a thin wrapper to ensure annotation type safety, since
annotations are stored in a Map as Objects.
putAnnotation in interface Aastkey - Key under which to store the annotation.annotation - Arbitrary floating point numeric value.public void putAnnotation(java.lang.String key,
java.lang.Double annotation,
int index)
putAnnotation in interface Aastkey - Key under which to store the annotation.annotation - Arbitrary floating point numeric value.index - The index of -1 indicates an addition to the end of the array.
Otherwise this is the explicit zero-based index at which to
add the annotation.public void putAnnotation(java.lang.String key,
java.lang.Long annotation)
This is just a thin wrapper to ensure annotation type safety, since
annotations are stored in a Map as Objects.
putAnnotation in interface Aastkey - Key under which to store the annotation.annotation - Arbitrary integral numeric value.public void putAnnotation(java.lang.String key,
java.lang.Long annotation,
int index)
putAnnotation in interface Aastkey - Key under which to store the annotation.annotation - Arbitrary integral numeric value.index - The index of -1 indicates an addition to the end of the array.
Otherwise this is the explicit zero-based index at which to
add the annotation.public void putAnnotation(java.lang.String key,
java.lang.Boolean annotation)
This is just a thin wrapper to ensure annotation type safety, since
annotations are stored in a Map as Objects.
putAnnotation in interface Aastkey - Key under which to store the annotation.annotation - Arbitrary boolean value.public void putAnnotation(java.lang.String key,
java.lang.Boolean annotation,
int index)
putAnnotation in interface Aastkey - Key under which to store the annotation.annotation - Arbitrary boolean value.index - The index of -1 indicates an addition to the end of the array.
Otherwise this is the explicit zero-based index at which to
add the annotation.public void putAnnotation(java.lang.String key,
java.util.List<java.lang.Object> annotation)
String
Double
Long
Boolean
putAnnotation in interface Aastkey - Key under which to store the annotation.annotation - list of annotations of the same, supported type.public void putAnnotationObject(java.lang.String key,
java.lang.Object annotation)
InMemoryRegistryPlugin since this is the only plugin
that does not truly serialize the nodes. The other plugins require the the annotation
objects to be serializable so only a small set of objects are supported.putAnnotationObject in interface Aastkey - The name of the annotation.annotation - The value for the annotation. Any type of object can be stored as long it is not
required to be saved.public java.lang.Object removeAnnotation(java.lang.String key)
List) or it may be a
scalar value.removeAnnotation in interface Aastkey - Key under which the annotation is stored.null if none was found.public java.lang.Object removeAnnotation(java.lang.String key,
int index)
removeAnnotation in interface Aastkey - Key under which the annotation is stored.index - The index of -1 indicates an addition to the end of the array.
Otherwise this is the explicit zero-based index at which to
add the annotation.null if the
annotation doesn't exist, if the annotation is not an array or
if no element exists at the given index.public void clearAnnotations()
clearAnnotations in interface Aastpublic java.util.Iterator<java.lang.String> annotationKeys()
annotationKeys in interface Aastnull.public void fixups(Aast parent, java.lang.Long fileId) throws AstException
If the current node's ID is null, then this method will
use the AstManager.getNextNodeId(long) to obtain a valid ID that
will uniquely identify this node. This can only be done if the passed
in file ID is valid and not null.
No shadow nodes will be created using this version of the method. All hidden tokens will be dropped.
parent - Parent AST node to be assigned to the current node.fileId - The file ID of the source file.AstExceptionpublic void fixups(Aast parent, java.lang.Long fileId, boolean shadow) throws AstException
If the current node's ID is null, then this method will
use the AstManager.getNextNodeId(long) to obtain a valid ID that
will uniquely identify this node. This can only be done if the passed
in file ID is valid and not null.
parent - Parent AST node to be assigned to the current node.fileId - The file ID of the source file.shadow - true to create shadow nodes from hidden tokens.
false to drop hidden tokens without creating any
shadow nodes.AstExceptionpublic void fixupParent(Aast parent)
parent - The parent for this node.public void intern()
String objects.
Since all these objects must be retrieved and re-stored, this method will be expensive for a large tree. It should only be invoked on trees which will remain in long term memory.
public java.lang.String toString()
toString in interface antlr.collections.ASTtoString in class antlr.BaseASTpublic java.lang.String toStringVerbose()
toStringVerbose in interface Aastpublic java.lang.String dumpSimpleTree()
public java.lang.String dumpTree()
public java.lang.String dumpTree(boolean annotations)
public Aast getLeftShadowNode()
getLeftShadowNode in interface Aastnull if no such node exists.public Aast getRightShadowNode()
getRightShadowNode in interface Aastnull if no such node exists.public Aast getLeftmost()
getLeftmost in interface Aastthis if there are
no children.public Aast getRightmost()
getRightmost in interface Aastthis if there are
no children.public Aast getLeftAdjacent()
getLeftAdjacent in interface Aastnull if there are
no nodes on the left.public Aast getRightAdjacent()
getRightAdjacent in interface Aastnull if there are
no nodes on the right.public ShadowNode getLeftShadow()
getLeftShadow in interface Aastnull if no such node exists.public ShadowNode getRightShadow()
getRightShadow in interface Aastnull if no such node exists.public ShadowNode getLeftmostShadow()
getLeftmostShadow in interface Aastnull if no such node exists.public ShadowNode getRightmostShadow()
getRightmostShadow in interface Aastnull if no such node exists.public java.util.Iterator<ShadowNode> getShadowNodeList()
getShadowNodeList in interface Aastnull if none exist.public TreeLocal getLocal()
public void setLocal(TreeLocal local)
public boolean compareWith(Aast other)
this node as a root and
compare it with given subtree. Subtrees considered identical if both
contain identical nodes organized in the same order. Two nodes are
considered identical if their type and text are identical. The order of
subtrees is defined by iterator provided by iterator() method.
The comparison of token text is case sensitive. For a case insensitive
comparison, use the compareWith(Aast,boolean) method variant.
compareWith in interface Aastother - The subtree to compare with.true if subtrees are identical and
false otherwise.public boolean compareWith(Aast other, boolean ignoreCase)
this node as a root and
compare it with given subtree. Subtrees considered identical if both
contain identical nodes organized in the same order. Two nodes are
considered identical if their type and text are identical. The order of
subtrees is defined by iterator provided by iterator() method.compareWith in interface Aastother - The subtree to compare with.ignoreCase - true to ignore case in the token text comparison;
false for a case sensitive comparison.true if subtrees are identical and
false otherwise.public void setRuntimeAnnotation(int key,
java.lang.Object value)
setRuntimeAnnotation in interface Aastkey - The annotation key.value - The annotation value.public java.lang.Object getRuntimeAnnotation(int key)
getRuntimeAnnotation in interface Aastkey - The annotation key.public boolean isRuntimeAnnotation(int key)
isRuntimeAnnotation in interface Aastkey - The annotation key.private Aast farthest(boolean right)
right - true to search rightwards, false to search leftwards.this if there are no children.private Aast nearest(boolean right)
This is an expensive operation as we cannot look down to find the answer, the answer may be enclosed within an arbitrary number of parents above (possibly all the way to the root). For this reason, we iterate through all nodes in the tree to find the answer.
right - true to search rightwards, false to search leftwards.null if there is no node in that direction.private AnnotatedAst createNode(antlr.Token token, Aast parent)
token - The data with which to populate the node.parent - The parent for the newly created node.null if there is an
error.private Aast[] getParentChain(Aast node)
node - The root node to get parent chain.private void createShadowNodes(java.lang.Long fileId)
original-token annotation and create
shadow nodes from the hidden before and after tokens if they exist. The entire chain
of hidden tokens will be walked and created. Each shadow node will have a valid ID and
will have the left and right IDs set as appropriate. Then the temporary original token
annotation will be removed so that there is never an attempt to persist it to file.
Both the parent and the ID must be assigned before this method is called.
fileId - The file ID of the source file.private java.lang.String getPath(int max)
BLOCK/STATEMENT/KW_IF/
represents the following path:
ROOT [type=BLOCK]
|
NODE A [type=STATEMENT]
|
NODE B [type=KW_IF]
The string uniquely identifies the path from this node back to the ancestor node, but is not
necessarily unique when traversed from the ancestor to this node. How far up the tree we
travel is determined by the max parameter.max - The maximum number of characters to be included in the returned path, or a
non-positive integer to indicate that all nodes up to and including the root
should be included in the path.max > 0, as much of that
path that can fit within max characters.private Aast getFirstChild(boolean honorHidden)
honorHidden
flag is false, or the first non-hidden child if the
honorHidden flag is true.honorHidden - If true, the hidden attribute of
the node will be honored. This means that the node will not
be returned and instead the first non-hidden sibling will be
returned.honorHidden mode),
or otherwise the first child. Returns null if no
non-hidden children exist (in honorHidden mode)
or whenever no children of any kind exist.private Aast getNextSibling(boolean honorHidden)
honorHidden
flag is false, or the next non-hidden sibling if the
honorHidden flag is true.honorHidden - If true, the hidden attribute of
the node will be honored. This means that the node will not
be returned and instead the next non-hidden sibling will be
returned.honorHidden mode),
or otherwise the next child. Returns null if no
non-hidden siblings exist (in honorHidden mode)
or whenever no siblings of any kind exist.private boolean searchDown(java.lang.String[] list,
int index)
list - The list of token names in order from ancestor (leftmost)
to descendant (rightmost).index - The current segment of the path which must be tested.true.private boolean searchDown(java.lang.Object[] list,
int index)
list - The list of token types in order from ancestor (list[0]) to descendant
(list[N]).index - The current segment of the path which must be tested.true.private static boolean searchUp(AnnotatedAst node, java.lang.Object[] path, int k, boolean absolute)
node - The node to start the search.path - The comparison path.k - The index in the path to search.absolute - Flag indicating that this path must match to the root node.true if the source path starts with the root node and ends with the target path.private boolean searchUp(java.lang.String source,
java.lang.String target)
source - The actual path upward.target - The comparison path.true if the source path ends with the target
path.private void driveFixups(Aast child) throws AstException
child - The child node to fixup.AstExceptionprivate void putAnnotationImpl(java.lang.String key,
java.lang.Object annotation)
key - Key under which to store the annotation.annotation - Arbitrary annotation value.private boolean putAnnotationImpl(java.lang.String key,
java.lang.Object annotation,
int index)
key - Key under which to store the annotation.annotation - Arbitrary annotation value.index - The index of -1 indicates an addition to the end of the array. Otherwise this is
the explicit zero-based index at which to add the annotation. Any element at that
location will be replaced.true if the element was added.private void extractTokenData(antlr.Token token)
ManagedHiddenStreamToken, then
also store the input token as an "original-token" annotation. Otherwise, that token will
not be stored.
The original token will be temporarily stored before being used to create the shadow nodes by the fixup process. This is a hack but it is the simplest and cleanest approach available until better hooks exist for processing IDs and parent linkages during node creation. Since the shadow nodes cannot be fully processed until the node IDs are assigned, the input token instance must be retained with the node until that time. Rather than make a new data member, a temporary annotation is used and will be removed when the shadow nodes are created and stored in the tree-local data store. These temporary annotations will never be persisted to disk.
It is important to leave behind the actual token for each node because AST nodes are created as the lexer stream is processed but subsequent token processing can modify the hidden token state of the orignial token for prior nodes. This is done to patch dropped tokens back into the hidden token streams (we are putting "Humpty Dumpty" back together again). Thus, we cannot extract the hidden token linkages during this method call, but only when fixups are being processed since everything will be patched by that time.
token - Token from which information is to be extracted.