polyglot.visit
Class NodeScrambler
java.lang.Object
polyglot.visit.NodeVisitor
polyglot.visit.NodeScrambler
public class NodeScrambler
- extends NodeVisitor
The NodeScrambler
is test case generator of sorts. Since it
is ofter useful to introduce ``random'' errors into source code, this
class provides a way of doing so in a semi-structed 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.
Nested Class Summary |
class |
NodeScrambler.FirstPass
Scans throught the AST, create a list of all nodes present, along with
the set of parents for each node in the tree. |
Constructor Summary |
NodeScrambler()
|
NodeScrambler(long seed)
Create a new NodeScrambler with the given random number
generator seed. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
fp
public NodeScrambler.FirstPass fp
pairs
protected java.util.HashMap pairs
nodes
protected java.util.LinkedList nodes
currentParents
protected java.util.LinkedList currentParents
seed
protected long seed
ran
protected java.util.Random ran
scrambled
protected boolean scrambled
cw
protected CodeWriter cw
NodeScrambler
public NodeScrambler()
NodeScrambler
public NodeScrambler(long seed)
- Create a new
NodeScrambler
with the given random number
generator seed.
getSeed
public long getSeed()
override
public Node override(Node n)
- Description copied from class:
NodeVisitor
- Given a tree rooted at
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.
- Overrides:
override
in class NodeVisitor
- Parameters:
n
- The root of the subtree to be traversed.
- Returns:
- A node if normal traversal is to stop,
null
if it
is to continue.
coinFlip
protected boolean coinFlip()
potentialScramble
protected Node potentialScramble(Node n)