Newer
Older
package tfm.exec;
import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.visitor.GenericVisitor;
import tfm.graphs.CFGGraph;
import tfm.graphs.Graph;
import tfm.graphs.PDGGraph;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
public class Main {
public static final String PROGRAM = Utils.PROGRAMS_FOLDER + "pdg/Example2.java";
public static final String METHOD = "";
public static final String GRAPH = GraphLog.PDG;
public static void main(String[] args) throws IOException {
JavaParser.getStaticConfiguration().setAttributeComments(false);
// File
File file = new File(PROGRAM);
Node root = JavaParser.parse(file);
if (!METHOD.isEmpty()) {
Optional<MethodDeclaration> methodDeclarationOptional = root.findFirst(MethodDeclaration.class,
methodDeclaration -> Objects.equals(methodDeclaration.getNameAsString(), METHOD));
if (!methodDeclarationOptional.isPresent()) {
Logger.format("Method '%s' not found in '%s'. Exiting...", METHOD, PROGRAM);
return;
}
root = methodDeclarationOptional.get();
}
// GraphLog
GraphLog<?, ?> graphLog = getGraphLog(args.length == 1 ? args[0] : GRAPH);
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
long t0 = System.nanoTime();
graphLog.visit(root);
long tf = System.nanoTime();
long tt = tf - t0;
graphLog.log();
graphLog.generatePNGs();
graphLog.openVisualRepresentation();
Logger.log();
Logger.format("Graph generated in %.2f ms", tt / 10e6);
}
private static GraphLog<?, ?> getGraphLog(String graph) throws IOException {
GraphLog<?, ?> graphLog = null;
switch (graph) {
case GraphLog.CFG:
graphLog = new CFGLog();
break;
case GraphLog.PDG:
graphLog = new PDGLog();
break;
default:
Logger.log("Unkown graph type");
System.exit(1);
}
return graphLog;
}
}