Class TypeVisualizer


  • public class TypeVisualizer
    extends java.lang.Object
    TypeVisualizer prints AnnotatedTypeMirrors as a directed graph where each node is a type and an arrow is a reference. Arrows are labeled with the relationship that reference represents (e.g. an arrow marked "extends" starts from a type variable or wildcard type and points to the upper bound of that type).

    Currently, to use TypeVisualizer just insert an if statement somewhere that targets the type you would like to print: e.g.

    
     if (type.getKind() == TypeKind.EXECUTABLE && type.toString().contains("methodToPrint")) {
         TypeVisualizer.drawToPng("/Users/jburke/Documents/tmp/method.png", type);
     }
     
    Be sure to remove such statements before committing your changes.
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeVisualizer()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void drawToDot​(java.io.File dest, AnnotatedTypeMirror type)
      Creates a dot file at dest that contains a digraph for the structure of type.
      static void drawToDot​(java.lang.String dest, AnnotatedTypeMirror type)
      Creates a dot file at dest that contains a digraph for the structure of type.
      static void drawToPng​(java.io.File dest, AnnotatedTypeMirror type)
      Draws a dot file for type in a temporary directory then calls the "dot" program to convert that file into a png at the location dest.
      static void drawToPng​(java.lang.String dest, AnnotatedTypeMirror type)
      Draws a dot file for type in a temporary directory then calls the "dot" program to convert that file into a png at the location dest.
      static void execDotToPng​(java.io.File dotFile, java.io.File pngFile)
      Converts the given dot file to a png file at the specified location.
      static boolean printTypevarToDotIfMatches​(AnnotatedTypeMirror.AnnotatedTypeVariable typeVariable, java.util.List<java.lang.String> typeVarNames, java.lang.String directory)
      If the name of typeVariable matches one in the list of typeVarNames, then print typeVariable to a dot file at directory/varName.
      static boolean printTypevarToPngIfMatches​(AnnotatedTypeMirror.AnnotatedTypeVariable typeVariable, java.util.List<java.lang.String> typeVarNames, java.lang.String directory)
      If the name of typeVariable matches one in the list of typeVarNames, then print typeVariable to a png file at directory/varName.png.
      • Methods inherited from class java.lang.Object

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

      • TypeVisualizer

        public TypeVisualizer()
    • Method Detail

      • drawToDot

        public static void drawToDot​(java.io.File dest,
                                     AnnotatedTypeMirror type)
        Creates a dot file at dest that contains a digraph for the structure of type.
        Parameters:
        dest - the destination dot file
        type - the type to be written
      • drawToDot

        public static void drawToDot​(java.lang.String dest,
                                     AnnotatedTypeMirror type)
        Creates a dot file at dest that contains a digraph for the structure of type.
        Parameters:
        dest - the destination dot file, this string will be directly passed to new File(dest)
        type - the type to be written
      • drawToPng

        public static void drawToPng​(java.io.File dest,
                                     AnnotatedTypeMirror type)
        Draws a dot file for type in a temporary directory then calls the "dot" program to convert that file into a png at the location dest. This method will fail if a temp file can't be created.
        Parameters:
        dest - the destination png file
        type - the type to be written
      • drawToPng

        public static void drawToPng​(java.lang.String dest,
                                     AnnotatedTypeMirror type)
        Draws a dot file for type in a temporary directory then calls the "dot" program to convert that file into a png at the location dest. This method will fail if a temp file can't be created.
        Parameters:
        dest - the destination png file, this string will be directly passed to new File(dest)
        type - the type to be written
      • execDotToPng

        public static void execDotToPng​(java.io.File dotFile,
                                        java.io.File pngFile)
        Converts the given dot file to a png file at the specified location. This method calls the program "dot" from Runtime.exec and will fail if "dot" is not on your class path.
        Parameters:
        dotFile - the dot file to convert
        pngFile - the destination of the resultant png file
      • printTypevarToDotIfMatches

        public static boolean printTypevarToDotIfMatches​(AnnotatedTypeMirror.AnnotatedTypeVariable typeVariable,
                                                         java.util.List<java.lang.String> typeVarNames,
                                                         java.lang.String directory)
        If the name of typeVariable matches one in the list of typeVarNames, then print typeVariable to a dot file at directory/varName.
        Returns:
        true if the type variable was printed, otherwise false
      • printTypevarToPngIfMatches

        public static boolean printTypevarToPngIfMatches​(AnnotatedTypeMirror.AnnotatedTypeVariable typeVariable,
                                                         java.util.List<java.lang.String> typeVarNames,
                                                         java.lang.String directory)
        If the name of typeVariable matches one in the list of typeVarNames, then print typeVariable to a png file at directory/varName.png.
        Returns:
        true if the type variable was printed, otherwise false