public class Resolver
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Long,Aast> |
astMap
Map of ids to tree nodes.
|
private java.util.Set<Aast> |
view
Set of filtered results which define a view of the original tree.
|
Constructor and Description |
---|
Resolver(java.util.Map<java.lang.Long,Aast> astMap)
Construct an instance, optionally providing a pre-initialized ID to tree
map.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addPathToViewFrom(Aast node,
long type)
Add to the filtered view of ASTs all of the copy nodes
which form the path from an ancestor node of type
type
to the given AST. |
boolean |
addToView(java.lang.Long id)
Add an arbitrary AST node to the filtered view of AST nodes associated
with the current ruleset run.
|
void |
addTreeToView(Aast root,
int maxLevels)
Add the all nodes of the given sub-tree to the view, descending at most
maxLevels generations deep. |
Aast |
getAst(java.lang.Long id)
Get the AST with the specified ID.
|
void |
registerAst(Aast ast)
Register an AST, so that it is accessible by its unique ID with the
getAst(java.lang.Long) method. |
void |
registerTree(Aast root)
Helper to add an entire subtree (rooted at the specified AST node) to
the AST registry.
|
void |
reset()
Clear the contents of the view.
|
(package private) java.util.Iterator |
view()
Return an iterator on the filtered view of ASTs currently associated
with this resolver.
|
private java.util.Map<java.lang.Long,Aast> astMap
private java.util.Set<Aast> view
public Resolver(java.util.Map<java.lang.Long,Aast> astMap)
astMap
- Map of IDs to tree nodes or null
.public void reset()
public void registerAst(Aast ast)
getAst(java.lang.Long)
method.ast
- AST to be registered.java.lang.NullPointerException
- If ast
has not yet been assigned a unique ID.public void registerTree(Aast root)
root
- Root node of the tree to be added.public Aast getAst(java.lang.Long id)
id
- ID which uniquely identifies the desired AST.id
, or null
if no node is found for id
.public boolean addToView(java.lang.Long id)
true
if the AST is valid (and thus was added),
false
otherwise.public void addTreeToView(Aast root, int maxLevels)
maxLevels
generations deep.root
- Node that is the root of the sub-tree to add to the view.maxLevels
- Number of generations to be added to the result set,
beginning with the current AST. To add only the current
AST, specify 1
(or better yet, use addToView(java.lang.Long)
).public boolean addPathToViewFrom(Aast node, long type)
type
to the given AST. The nodes are added in root to leaf order.
If an ancestor node of type type
does not exist, no nodes
are added (not even the current one).node
- Node from which to start the search.type
- Ancestor token type which marks the beginning of the path.true
if an ancestor of type type
was found and the path of nodes was successfully added to the
filtered view, else false
.java.util.Iterator view()
This method provides the mechanism which allows the next walker in a pipeline to iterate over the filtered results of the previous walker's processing of the tree hierarchy.
The collection underlying this view is replaced with an empty
collection before each walker in the pipeline is processed. However,
it is safe to iterate over the view returned by this method after this
occurs, because a new collection is used for each pass, and the
Iterator
instance returned by this method continues to be
associated with the results collection which was in use at the time
it was called.