|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectxtc.tree.Visitor
xtc.tree.Transducer
public class Transducer
Visitor to convert trees of generic nodes into methods that
programmatically create the trees. Trees may contain generic nodes
that represent pattern variables. During transduction, pattern
variable are replaced with method arguments of the same names. In
general, a variable represents a single child of a newly created
generic node. However, if the variable's type is
List<T>, all of the list's elements are directly
added as children to the newly created generic node. Any node
representing a pattern variable must have exactly one child that is
a string representing the variable's name.
| Field Summary | |
|---|---|
protected Printer |
printer
The printer. |
protected int |
varcount
The temporary variable count. |
protected java.util.Map<java.lang.String,java.lang.String> |
variables
The mapping from pattern variable names to their types. |
| Constructor Summary | |
|---|---|
Transducer(Printer printer)
Create a new transducer. |
|
Transducer(Printer printer,
java.util.Map<java.lang.String,java.lang.String> variables)
Create a new transducer. |
|
| Method Summary | |
|---|---|
java.lang.String |
getVariableName(Node n)
Get the pattern variable's name. |
java.lang.String |
getVariableType(Node n)
Get the pattern variable's type. |
boolean |
isListType(java.lang.String t)
Determine whether the specified type is a list type. |
boolean |
isPatternVariable(Node n)
Determine whether the specified node represents a pattern variable. |
void |
process(java.lang.String method,
Node n)
Process the specified node. |
java.lang.String |
toLiteral(java.lang.Object o,
java.lang.String var)
Convert the specified object to a literal. |
GNode |
toPatternVariable(Node n)
Ensure that the specified node is a well-formed pattern variable. |
java.lang.String |
visit(GNode n)
Visit the specified generic node. |
| Methods inherited from class xtc.tree.Visitor |
|---|
dispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visit |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final Printer printer
protected final java.util.Map<java.lang.String,java.lang.String> variables
protected int varcount
| Constructor Detail |
|---|
public Transducer(Printer printer)
printer - The printer.
public Transducer(Printer printer,
java.util.Map<java.lang.String,java.lang.String> variables)
null) to indicate
that all tree nodes are literal, i.e., do not contain any "holes"
that are filled during creation.
printer - The printer.variables - The mapping from node names representing pattern
variables to their values' types.| Method Detail |
|---|
public boolean isPatternVariable(Node n)
n - The node.
true if it represents a pattern variable.public GNode toPatternVariable(Node n)
n - The node.
java.lang.IllegalArgumentException - Signals that the specified node
is not a pattern variable or is a malformed pattern variable.public java.lang.String getVariableName(Node n)
n - The node.
java.lang.IllegalArgumentException - Signals that the node does not
represent a pattern variable or is malformed.public java.lang.String getVariableType(Node n)
n - The node.
java.lang.IllegalArgumentException - Signals that the node does not
represent a pattern variable or is malformed.public boolean isListType(java.lang.String t)
t - The type.
true if the specified type is a list type.
public java.lang.String toLiteral(java.lang.Object o,
java.lang.String var)
null and the object is a node, the
object must be a pattern variable.
o - The object.var - The variable name for nodes that are not pattern
variables.
java.lang.IllegalArgumentException - Signals that the specified object
is not recognized.
public void process(java.lang.String method,
Node n)
method - The method name.n - The node.
java.lang.IllegalArgumentException - Signals that the specified is
not a generic node or that it is a pattern variable.public java.lang.String visit(GNode n)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||