public class NodeScrambler extends NodeVisitor
NodeScrambler
is test case generator of sorts. Since it
is often useful to introduce ``random'' errors into source code, this
class provides a way of doing so in a semi-structured manner. The process
takes place in two phases. First, a "FirstPass" is made to collect
a list of nodes and their parents. Then a second pass is made to randomly
replace a branch of the tree with another suitable branch.Modifier and Type | Class and Description |
---|---|
class |
NodeScrambler.FirstPass
Scans through the AST, create a list of all nodes present, along with
the set of parents for each node in the tree.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.LinkedList<Node> |
currentParents |
protected CodeWriter |
cw |
NodeScrambler.FirstPass |
fp |
protected java.util.LinkedList<Node> |
nodes |
protected java.util.HashMap<Node,java.util.LinkedList<Node>> |
pairs |
protected java.util.Random |
ran |
protected boolean |
scrambled |
protected long |
seed |
Constructor and Description |
---|
NodeScrambler(JLang lang) |
NodeScrambler(JLang lang,
long seed)
Create a new
NodeScrambler with the given random number
generator seed. |
Modifier and Type | Method and Description |
---|---|
protected boolean |
coinFlip() |
long |
getSeed() |
Node |
override(Node n)
Given a tree rooted at
n , the visitor has the option of
overriding all traversal of the children of n . |
protected Node |
potentialScramble(Node n) |
public NodeScrambler.FirstPass fp
protected java.util.LinkedList<Node> nodes
protected java.util.LinkedList<Node> currentParents
protected long seed
protected java.util.Random ran
protected boolean scrambled
protected CodeWriter cw
public NodeScrambler(JLang lang)
public NodeScrambler(JLang lang, long seed)
NodeScrambler
with the given random number
generator seed.public long getSeed()
public Node override(Node n)
NodeVisitor
n
, the visitor has the option of
overriding all traversal of the children of n
. If no
changes were made to n
and the visitor wishes to prevent
further traversal of the tree, then it should return n
. If
changes were made to the subtree, then the visitor should return a
copy of n
with appropriate changes. Finally, if the
visitor does not wish to override traversal of the subtree rooted at
n
, then it should return null
.
This method is typically called by the method
override(parent, n)
. If a subclass overrides the
method override(parent, n)
then this method
may not be called.
override
in class NodeVisitor
n
- The root of the subtree to be traversed.null
if it
is to continue.protected boolean coinFlip()