Class CoordinatesPrinter

java.lang.Object
org.openrewrite.java.CoordinatesPrinter

public class CoordinatesPrinter extends Object
Utility to print a compilation unit with tree coordinates embedded in the output. This can be useful to discover the location within the source code that the coordinate represents.
  • Field Details

  • Constructor Details

    • CoordinatesPrinter

      public CoordinatesPrinter()
  • Method Details

    • printCoordinates

      public static String printCoordinates(J.CompilationUnit cu, @Nullable @Nullable Class<? extends J> cursorFilter)
      This will print out the compilation unit and embed the tree coordinates (at each Space position). If a filter is supplied, the printer will only print coordinates for the tree elements of that given type.

      See printCoordinatesWithColor(J.CompilationUnit, Class) for a variant of this method that will output the string with ASCII color codes.

      Parameters:
      cu - The compilation unit to print
      cursorFilter - An optional cursor filter.
      Returns:
      The printed tree.
    • printCoordinatesWithColor

      public static String printCoordinatesWithColor(J.CompilationUnit cu, Class<? extends J> cursorFilter)
      This will print out the compilation unit and embed the tree coordinates (at each Space position). If a filter is supplied, the printer will only print coordinates for the tree elements of that given type. This variant also uses ANSI Color codes to better highlight the differences between the coordinates and the actual source code.
      Parameters:
      cu - The compilation unit to print
      cursorFilter - An optional cursor filter.
      Returns:
      The printed tree.