public abstract class AbstractPatternWorker extends java.lang.Object implements PatternWorker
The most important usage note is that it is not possible for sub-classes
to pass the libraries
array of Object
instances
(the list of exported libraries to register) in the constructor of a
super class. For this reason, a separate setLibraries
method has been provided which must be called in the sub-class'
constructor, after the super
constructor has been
invoked.
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
library
Library object (exports functions/variables to rulesets) to register
|
protected AstSymbolResolver |
resolver
Provides access to source/target AST nodes and is our interface for
registering libraries and functions.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractPatternWorker()
Default constructor, which can only be called by a sub-class.
|
Modifier and Type | Method and Description |
---|---|
void |
finish()
Hook to provide termination processing for a pattern worker.
|
protected Aast |
getCopy()
Get the current copy AST.
|
java.lang.Object |
getLibrary()
Get the user function/property library exposed by this pattern worker.
|
protected Aast |
getSource()
Get the current source AST.
|
void |
initialize()
Obtains the reference to the
resolver and initializes
all exported libraries. |
void |
registerTree(Aast ast)
Register the given tree with the AST resolver.
|
java.lang.Object |
resolveConstant(java.lang.String constant)
This method is called each time the pattern engine needs to resolve
a string constant into a numeric, boolean, or string literal value.
|
protected void |
setLibrary(java.lang.Object library)
Sets the library that must be registered.
|
void |
visitAst(Aast ast)
This method is called each time a new AST is visited, just before the
pattern engine processes that AST.
|
protected AstSymbolResolver resolver
private java.lang.Object library
protected AbstractPatternWorker()
public void initialize()
resolver
and initializes
all exported libraries.initialize
in interface PatternWorker
public void registerTree(Aast ast)
ast
- Tree to register.public void finish()
finish
in interface PatternWorker
public java.lang.Object getLibrary()
getLibrary
in interface PatternWorker
null
if the pattern
worker implementation does not need to register a library.PatternWorker.getLibrary()
public java.lang.Object resolveConstant(java.lang.String constant)
It must return an object of the following type (or null
):
resolveConstant
in interface PatternWorker
constant
- A string representing a constant to be resolved.null
.public void visitAst(Aast ast)
visitAst
in interface PatternWorker
ast
- The root node of the source AST about to be processed by the
pattern engine.protected void setLibrary(java.lang.Object library)
library
- Instance of exported libraries to be registered with the
resolver
. Must not be null
.java.lang.IllegalArgumentException
- if library
is null
.protected Aast getSource()
protected Aast getCopy()