Class TypeVisualizer

java.lang.Object
org.checkerframework.common.util.TypeVisualizer

public class TypeVisualizer extends 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 Details

    • TypeVisualizer

      public TypeVisualizer()
  • Method Details

    • drawToDot

      public static void drawToDot(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(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(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(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(File dotFile, 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, List<String> typeVarNames, 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, List<String> typeVarNames, 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