Skip to content

Commit b27bc83

Browse files
committed
Add a dot exporter for the class graph
1 parent 7adc484 commit b27bc83

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package es.upv.mist.slicing.cli;
2+
3+
import es.upv.mist.slicing.graphs.ClassGraph;
4+
import org.jgrapht.nio.Attribute;
5+
import org.jgrapht.nio.dot.DOTExporter;
6+
7+
import java.util.Map;
8+
9+
public class ClassGraphLog {
10+
protected DOTExporter<ClassGraph.Vertex<?>, ClassGraph.ClassArc> getDOTExporter() {
11+
DOTExporter<ClassGraph.Vertex<?>, ClassGraph.ClassArc> dot = new DOTExporter<>();
12+
dot.setVertexAttributeProvider(this::attributes);
13+
dot.setEdgeAttributeProvider(this::attributes);
14+
return dot;
15+
}
16+
17+
protected Map<String, Attribute> attributes(ClassGraph.Vertex<?> vertex) {
18+
DOTAttributes res = new DOTAttributes();
19+
res.set("label", vertex.toString());
20+
return res.build();
21+
}
22+
23+
protected Map<String, Attribute> attributes(ClassGraph.ClassArc arc) {
24+
DOTAttributes res = new DOTAttributes();
25+
return res.build();
26+
}
27+
}

sdg-core/src/main/java/es/upv/mist/slicing/graphs/ClassGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ protected void addClassEdges(Vertex<ClassOrInterfaceDeclaration> v) {
393393

394394
/** A vertex containing the declaration it represents. It only exists because
395395
* JGraphT relies heavily on equals comparison, which may not be correct in declarations. */
396-
protected static class Vertex<T extends BodyDeclaration<?>> {
396+
public static class Vertex<T extends BodyDeclaration<?>> {
397397
// First ancestor common class in the JavaParser hierarchy for
398398
// ClassOrInterfaceDeclaration, FieldDeclaration and CallableDeclaration
399399
protected final T declaration;
@@ -423,7 +423,7 @@ public String toString() {
423423
}
424424
}
425425

426-
protected static class ClassArc extends Arc {
426+
public static class ClassArc extends Arc {
427427
/** An arc that connects a class with another one that inherits from it. */
428428
protected static class Extends extends ClassArc {}
429429
/** An arc that connects an interface to a class that implements it. */

0 commit comments

Comments
 (0)