Commit b27bc83e authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Add a dot exporter for the class graph

parent 7adc4847
Loading
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.cli;

import es.upv.mist.slicing.graphs.ClassGraph;
import org.jgrapht.nio.Attribute;
import org.jgrapht.nio.dot.DOTExporter;

import java.util.Map;

public class ClassGraphLog {
    protected DOTExporter<ClassGraph.Vertex<?>, ClassGraph.ClassArc> getDOTExporter() {
        DOTExporter<ClassGraph.Vertex<?>, ClassGraph.ClassArc> dot = new DOTExporter<>();
        dot.setVertexAttributeProvider(this::attributes);
        dot.setEdgeAttributeProvider(this::attributes);
        return dot;
    }

    protected Map<String, Attribute> attributes(ClassGraph.Vertex<?> vertex) {
        DOTAttributes res = new DOTAttributes();
        res.set("label", vertex.toString());
        return res.build();
    }

    protected Map<String, Attribute> attributes(ClassGraph.ClassArc arc) {
        DOTAttributes res = new DOTAttributes();
        return res.build();
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -393,7 +393,7 @@ public class ClassGraph extends DirectedPseudograph<ClassGraph.Vertex<?>, ClassG

    /** A vertex containing the declaration it represents. It only exists because
     *  JGraphT relies heavily on equals comparison, which may not be correct in declarations. */
    protected static class Vertex<T extends BodyDeclaration<?>> {
    public static class Vertex<T extends BodyDeclaration<?>> {
        // First ancestor common class in the JavaParser hierarchy for
        // ClassOrInterfaceDeclaration, FieldDeclaration and CallableDeclaration
        protected final T declaration;
@@ -423,7 +423,7 @@ public class ClassGraph extends DirectedPseudograph<ClassGraph.Vertex<?>, ClassG
        }
    }

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