use of org.jetbrains.kotlin.psi.KtElement in project kotlin by JetBrains.
the class CFGraphToDotFilePrinter method dumpDot.
public static void dumpDot(File file, Collection<Pseudocode> pseudocodes) throws FileNotFoundException {
File target = KotlinTestUtils.replaceExtension(file, "dot");
PrintStream out = new PrintStream(target);
out.println("digraph " + FileUtil.getNameWithoutExtension(file) + " {");
int[] count = new int[1];
Map<Instruction, String> nodeToName = new HashMap<Instruction, String>();
for (Pseudocode pseudocode : pseudocodes) {
dumpNodes(pseudocode.getInstructionsIncludingDeadCode(), out, count, nodeToName, Sets.newHashSet(pseudocode.getInstructions()));
}
int i = 0;
for (Pseudocode pseudocode : pseudocodes) {
String label;
KtElement correspondingElement = pseudocode.getCorrespondingElement();
if (correspondingElement instanceof KtNamedDeclaration) {
KtNamedDeclaration namedDeclaration = (KtNamedDeclaration) correspondingElement;
label = namedDeclaration.getName();
} else {
label = "anonymous_" + i;
}
out.println("subgraph cluster_" + i + " {\n" + "label=\"" + label + "\";\n" + "color=blue;\n");
dumpEdges(pseudocode.getInstructionsIncludingDeadCode(), out, count, nodeToName);
out.println("}");
i++;
}
out.println("}");
out.close();
}
Aggregations