Add README file intended to lower the barrier to entry for the next
[checker-flow-ng.git] / ControlFlowNode.java
blobf4a1af1ebfa0ca9c646c50902cea2a34dbf1db8a
1 import com.sun.source.tree.Tree;
2 import java.util.*;
4 /**
5 * A single node in a control flow graph.
6 * @author <a href="mailto:koenig@cs.washington.edu">David Matthew Jerry Koenig</a>
7 */
8 public class ControlFlowNode {
9 private ControlFlowNode elseSuccessor;
10 private Map<Throwable, ControlFlowNode> exceptionSuccessors;
11 private List<ControlFlowNode> predecessors;
12 private ControlFlowNode successor;
13 private Tree tree;
15 /**
16 * Sets up a control flow node with no predecessors or exception
17 * successors.
19 public ControlFlowNode(Tree tree) {
20 exceptionSuccessors = new HashMap<Throwable, ControlFlowNode>();
21 predecessors = new ArrayList<ControlFlowNode>();
22 this.tree = tree;
25 /**
26 * If the current node is a condition in a loop, if statement, or the
27 * ternary operator, the path to take if the condition is false.
29 public ControlFlowNode getElseSuccessor() {
30 return elseSuccessor;
33 /**
34 * A map from Throwables that may be thrown in the evaluation of this
35 * node to the path that execution will take on the throwing of the
36 * corresponding throwable.
38 public Map<Throwable, ControlFlowNode> getExceptionSuccessors() {
39 return exceptionSuccessors;
42 /**
43 * All incoming paths to this node.
45 public List<ControlFlowNode> getPredecessors() {
46 return predecessors;
49 /**
50 * The outgoing path of execution. If the current node is a condition in
51 * a loop, if statement, or the ternary operator, the path to take if the
52 * condition is true.
54 public ControlFlowNode getSuccessor() {
55 return successor;
58 /**
59 * Returns the node in the abstract syntax tree that corresponds to this
60 * node in the control flow graph.
62 public Tree getTree() {
63 return tree;
66 /**
67 * Sets the following node for normal execution. If the current node is a
68 * condition in a loop, if statement, or the ternary operator, the path to
69 * take if the condition is true.
71 public void setSuccessor(ControlFlowNode successor) {
72 this.successor = successor;
75 /**
76 * Sets the path to take if the current node is a condition in a loop, if
77 * statement, or the ternary operator, and the condition is false.
79 public void setElseSuccessor(ControlFlowNode elseSuccessor) {
80 this.elseSuccessor = elseSuccessor;
83 /**
84 * Sets the node in the abstract syntax tree that corresponds to this node
85 * in the control flow graph.
87 public void setTree(Tree tree) {
88 this.tree = tree;