throw new IllegalStateException("No common dominator found!");
}
public final void export(final File path) {
final PlainTextOutput output = new PlainTextOutput();
output.writeLine("digraph g {");
output.indent();
final Set<ControlFlowEdge> edges = new LinkedHashSet<>();
for (final ControlFlowNode node : _nodes) {
output.writeLine("\"%s\" [", nodeName(node));
output.indent();
output.writeLine(
"label = \"%s\\l\"",
escapeGraphViz(node.toString())
);
output.writeLine(", shape = \"box\"");
output.unindent();
output.writeLine("];");
edges.addAll(node.getIncoming());
edges.addAll(node.getOutgoing());
final ControlFlowNode endFinallyNode = node.getEndFinallyNode();
if (endFinallyNode != null) {
output.writeLine("\"%s\" [", nodeName(endFinallyNode));
output.indent();
output.writeLine(
"label = \"%s\"",
escapeGraphViz(endFinallyNode.toString())
);
output.writeLine("shape = \"box\"");
output.unindent();
output.writeLine("];");
edges.addAll(endFinallyNode.getIncoming());
edges.addAll(endFinallyNode.getOutgoing());
// edges.add(new ControlFlowEdge(node, endFinallyNode, JumpType.EndFinally));
}
}
for (final ControlFlowEdge edge : edges) {
final ControlFlowNode from = edge.getSource();
final ControlFlowNode to = edge.getTarget();
output.writeLine("\"%s\" -> \"%s\" [", nodeName(from), nodeName(to));
output.indent();
switch (edge.getType()) {
case Normal:
break;
case LeaveTry:
output.writeLine("color = \"blue\"");
break;
case EndFinally:
output.writeLine("color = \"red\"");
break;
case JumpToExceptionHandler:
output.writeLine("color = \"gray\"");
break;
default:
output.writeLine("label = \"%s\"", edge.getType());
break;
}
output.unindent();
output.writeLine("];");
}
output.unindent();
output.writeLine("}");
try (final OutputStreamWriter out = new FileWriter(path)) {
out.write(output.toString());
}
catch (IOException e) {
throw ExceptionUtilities.asRuntimeException(e);
}
}