Class LineNumberFormatter


  • public class LineNumberFormatter
    extends java.lang.Object
    A LineNumberFormatter is used to rewrite an existing .java file, introducing line number information. It can handle either, or both, of the following jobs:
    • Introduce line numbers as leading comments.
    • Stretch the file so that the line number comments match the physical lines.
    • Constructor Detail

      • LineNumberFormatter

        public LineNumberFormatter​(java.io.File file,
                                   java.util.List<LineNumberPosition> lineNumberPositions,
                                   java.util.EnumSet<LineNumberFormatter.LineNumberOption> options)
        Constructs an instance.
        Parameters:
        file - the file whose line numbers should be fixed
        lineNumberPositions - a recipe for how to fix the line numbers in 'file'.
        options - controls how 'this' represents line numbers in the resulting file
    • Method Detail

      • reformatFile

        public void reformatFile()
                          throws java.io.IOException
        Rewrites the file passed to 'this' constructor so that the actual line numbers match the recipe passed to 'this' constructor.
        Throws:
        java.io.IOException
      • breakLines

        private java.util.List<java.lang.String> breakLines​(java.util.List<LineNumberPosition> o_LineBrokenPositions)
                                                     throws java.io.IOException
        Processes _file, breaking apart any lines on which multiple line-number markers appear in different columns.
        Returns:
        the list of broken lines
        Throws:
        java.io.IOException
      • emitFormatted

        private void emitFormatted​(java.util.List<java.lang.String> brokenLines,
                                   java.util.List<LineNumberPosition> lineBrokenPositions)
                            throws java.io.IOException
        Throws:
        java.io.IOException