Add README file intended to lower the barrier to entry for the next
[checker-flow-ng.git] / FlowInvoker.java
blobc266ab0ae0963e6a89a0a1d63adf7d01740b8a42
1 import com.sun.source.util.AbstractTypeProcessor;
2 import com.sun.source.util.TreePath;
3 import java.util.Collections;
4 import java.util.Map;
5 import java.util.Set;
6 import javax.lang.model.SourceVersion;
7 import javax.lang.model.element.TypeElement;
9 public class FlowInvoker extends AbstractTypeProcessor {
10 // AbstractTypeProcessor delegation
11 @Override
12 public final void typeProcess(TypeElement element, TreePath tree) {
13 outputGraphviz(new GenerateControlFlow().scan(tree, null));
16 public final void outputGraphviz(ControlFlowNode node) {
17 // TODO: Recursion is bad, yo
19 if (node == null) {
20 System.out.println("// null node");
21 return;
24 String thisAddr = "n" + Integer.toString(System.identityHashCode(node));
26 ControlFlowNode successor = node.getSuccessor();
27 if (successor != null) {
28 System.out.println(String.format("%s->n%d",
29 thisAddr,
30 System.identityHashCode(successor)));
31 outputGraphviz(successor);
34 ControlFlowNode elseSuccessor = node.getElseSuccessor();
35 if (elseSuccessor != null) {
36 System.out.println(String.format("%s->%d",
37 thisAddr,
38 System.identityHashCode(elseSuccessor)));
39 outputGraphviz(elseSuccessor);
42 System.out.println(node.getExceptionSuccessors().size() + " exception successors");
43 for (Map.Entry<Throwable, ControlFlowNode> entry :
44 node.getExceptionSuccessors().entrySet()) {
45 ControlFlowNode exNode = entry.getValue();
46 if (exNode != null) {
47 System.out.println(String.format("%s->%d",
48 thisAddr,
49 System.identityHashCode(exNode)));
50 outputGraphviz(exNode);
54 System.out.println(node.getPredecessors().size() + " predecessors");
55 for (ControlFlowNode predecessor : node.getPredecessors()) {
56 if (predecessor != null) {
57 System.out.println(String.format("%s->%d",
58 thisAddr,
59 System.identityHashCode(predecessor)));
60 outputGraphviz(predecessor);
65 @Override
66 public final Set<String> getSupportedAnnotationTypes() {
67 return Collections.singleton("*");
70 @Override
71 public final SourceVersion getSupportedSourceVersion() {
72 return SourceVersion.RELEASE_7;