Class GraphvizDotfileGenerator


  • final class GraphvizDotfileGenerator
    extends java.lang.Object
    Builds a class graph visualization in Graphviz .dot file format.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String ANNOTATION_COLOR
      The color for annotations.
      private static java.lang.String INTERFACE_COLOR
      The color for interfaces.
      private static java.util.BitSet IS_UNICODE_WHITESPACE
      Which characters are Unicode whitespace.
      private static int PARAM_WRAP_WIDTH
      The wrap width for method parameters.
      private static java.lang.String STANDARD_CLASS_COLOR
      The color for standard classes.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static java.lang.String generateGraphVizDotFile​(ClassInfoList classInfoList, float sizeX, float sizeY, boolean showFields, boolean showFieldTypeDependencyEdges, boolean showMethods, boolean showMethodTypeDependencyEdges, boolean showAnnotations, boolean useSimpleNames, ScanSpec scanSpec)
      Generates a .dot file which can be fed into GraphViz for layout and visualization of the class graph.
      (package private) static java.lang.String generateGraphVizDotFileFromInterClassDependencies​(ClassInfoList classInfoList, float sizeX, float sizeY, boolean includeExternalClasses)
      Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.
      private static void htmlEncode​(java.lang.CharSequence unsafeStr, boolean turnNewlineIntoBreak, java.lang.StringBuilder buf)
      Encode HTML-unsafe characters as HTML entities.
      private static void htmlEncode​(java.lang.CharSequence unsafeStr, java.lang.StringBuilder buf)
      Encode HTML-unsafe characters as HTML entities.
      private static boolean isUnicodeWhitespace​(char c)
      Checks if a character is Unicode whitespace.
      private static void labelClassNodeHTML​(ClassInfo ci, java.lang.String shape, java.lang.String boxBgColor, boolean showFields, boolean showMethods, boolean useSimpleNames, ScanSpec scanSpec, java.lang.StringBuilder buf)
      Produce HTML label for class node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • STANDARD_CLASS_COLOR

        private static final java.lang.String STANDARD_CLASS_COLOR
        The color for standard classes.
        See Also:
        Constant Field Values
      • INTERFACE_COLOR

        private static final java.lang.String INTERFACE_COLOR
        The color for interfaces.
        See Also:
        Constant Field Values
      • ANNOTATION_COLOR

        private static final java.lang.String ANNOTATION_COLOR
        The color for annotations.
        See Also:
        Constant Field Values
      • PARAM_WRAP_WIDTH

        private static final int PARAM_WRAP_WIDTH
        The wrap width for method parameters.
        See Also:
        Constant Field Values
      • IS_UNICODE_WHITESPACE

        private static final java.util.BitSet IS_UNICODE_WHITESPACE
        Which characters are Unicode whitespace.
    • Constructor Detail

      • GraphvizDotfileGenerator

        private GraphvizDotfileGenerator()
        Constructor.
    • Method Detail

      • isUnicodeWhitespace

        private static boolean isUnicodeWhitespace​(char c)
        Checks if a character is Unicode whitespace.
        Parameters:
        c - the character
        Returns:
        true if the character is Unicode whitespace
      • htmlEncode

        private static void htmlEncode​(java.lang.CharSequence unsafeStr,
                                       boolean turnNewlineIntoBreak,
                                       java.lang.StringBuilder buf)
        Encode HTML-unsafe characters as HTML entities.
        Parameters:
        unsafeStr - The string to escape to make HTML-safe.
        turnNewlineIntoBreak - If true, turn '\n' into a break element in the output.
        buf - the buf
      • htmlEncode

        private static void htmlEncode​(java.lang.CharSequence unsafeStr,
                                       java.lang.StringBuilder buf)
        Encode HTML-unsafe characters as HTML entities.
        Parameters:
        unsafeStr - The string to escape to make HTML-safe.
        buf - the buf
      • labelClassNodeHTML

        private static void labelClassNodeHTML​(ClassInfo ci,
                                               java.lang.String shape,
                                               java.lang.String boxBgColor,
                                               boolean showFields,
                                               boolean showMethods,
                                               boolean useSimpleNames,
                                               ScanSpec scanSpec,
                                               java.lang.StringBuilder buf)
        Produce HTML label for class node.
        Parameters:
        ci - the class info
        shape - the shape to use
        boxBgColor - the box background color
        showFields - whether to show fields
        showMethods - whether to show methods
        useSimpleNames - whether to use simple names for classes in type signatures
        scanSpec - the scan spec
        buf - the buf
      • generateGraphVizDotFile

        static java.lang.String generateGraphVizDotFile​(ClassInfoList classInfoList,
                                                        float sizeX,
                                                        float sizeY,
                                                        boolean showFields,
                                                        boolean showFieldTypeDependencyEdges,
                                                        boolean showMethods,
                                                        boolean showMethodTypeDependencyEdges,
                                                        boolean showAnnotations,
                                                        boolean useSimpleNames,
                                                        ScanSpec scanSpec)
        Generates a .dot file which can be fed into GraphViz for layout and visualization of the class graph. The sizeX and sizeY parameters are the image output size to use (in inches) when GraphViz is asked to render the .dot file.
        Parameters:
        classInfoList - the class info list
        sizeX - the size X
        sizeY - the size Y
        showFields - whether to show fields
        showFieldTypeDependencyEdges - whether to show field type dependency edges
        showMethods - whether to show methods
        showMethodTypeDependencyEdges - whether to show method type dependency edges
        showAnnotations - whether to show annotations
        useSimpleNames - whether to use simple names for classes
        scanSpec - the scan spec
        Returns:
        the string
      • generateGraphVizDotFileFromInterClassDependencies

        static java.lang.String generateGraphVizDotFileFromInterClassDependencies​(ClassInfoList classInfoList,
                                                                                  float sizeX,
                                                                                  float sizeY,
                                                                                  boolean includeExternalClasses)
        Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph. The returned graph shows inter-class dependencies only. The sizeX and sizeY parameters are the image output size to use (in inches) when GraphViz is asked to render the .dot file. You must have called ClassGraph.enableInterClassDependencies() before scanning to use this method.
        Parameters:
        classInfoList - The list of nodes whose dependencies should be plotted in the graph.
        sizeX - The GraphViz layout width in inches.
        sizeY - The GraphViz layout width in inches.
        includeExternalClasses - If true, include any dependency nodes in the graph that are not themselves in classInfoList.
        Returns:
        the GraphViz file contents.
        Throws:
        java.lang.IllegalArgumentException - if this ClassInfoList is empty or ClassGraph.enableInterClassDependencies() was not called before scanning (since there would be nothing to graph).