Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package tfm.exec;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import guru.nidi.graphviz.engine.Format;
import guru.nidi.graphviz.engine.Graphviz;
import tfm.graphs.CFGGraph;
import tfm.graphs.Graph;
import tfm.visitors.CFGVisitor;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
public class CFGLog extends GraphLog<CFGGraph, CFGVisitor> {
@Override
public void visit(Node node) {
this.graph = new CFGGraph() {
@Override
protected String getRootNodeData() {
return "Start";
}
};
this.visitor = new CFGVisitor(graph);
node.accept(visitor, null);
}
@Override
void generatePNGs() throws IOException {
Graphviz.fromString(graph.toGraphvizRepresentation())
.render(Format.PNG)
.toFile(new File("./out/cfg.png"));
}
@Override
public void openVisualRepresentation() throws IOException {
new ProcessBuilder(Arrays.asList("xdg-open", "./out/cfg.png")).start();
}
}