Class CoordinatesPrinter


  • public class CoordinatesPrinter
    extends java.lang.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.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String printCoordinates​(org.openrewrite.java.tree.J.CompilationUnit cu, @Nullable java.lang.Class<? extends org.openrewrite.java.tree.J> cursorFilter)
      This will print out the compilation unit and embed the tree coordinates (at each Space position).
      static java.lang.String printCoordinatesWithColor​(org.openrewrite.java.tree.J.CompilationUnit cu, java.lang.Class<? extends org.openrewrite.java.tree.J> cursorFilter)
      This will print out the compilation unit and embed the tree coordinates (at each Space position).
      • Methods inherited from class java.lang.Object

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

      • ANSI_FOREGROUND_WHITE

        public static final java.lang.String ANSI_FOREGROUND_WHITE
        See Also:
        Constant Field Values
      • ANSI_FOREGROUND_GREY

        public static final java.lang.String ANSI_FOREGROUND_GREY
        See Also:
        Constant Field Values
      • ANSI_BACKGROUND_GREEN

        public static final java.lang.String ANSI_BACKGROUND_GREEN
        See Also:
        Constant Field Values
    • Constructor Detail

      • CoordinatesPrinter

        public CoordinatesPrinter()
    • Method Detail

      • printCoordinates

        public static java.lang.String printCoordinates​(org.openrewrite.java.tree.J.CompilationUnit cu,
                                                        @Nullable
                                                        @Nullable java.lang.Class<? extends org.openrewrite.java.tree.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 java.lang.String printCoordinatesWithColor​(org.openrewrite.java.tree.J.CompilationUnit cu,
                                                                 java.lang.Class<? extends org.openrewrite.java.tree.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.