Package sc.parser

Class GenFileLineIndex

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class GenFileLineIndex
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    Used for storing the line mapping info for one file generated from a list of src files used to produce the generated file It can be used in two different modes. If you have already generated the file and have the gen-statements and the offsets of those statements, you can provide the contents and an index is built to map the offsets to line numbers. If you are generating statements on the fly from a template and don't have the generated statement, you can just manually add the mapping with the generated line number directly. In this case, you must set numLines once you are finished and before you save or use that - since the mappings may not include the total number of lines in the file and we need numLines in appendIndex()
    See Also:
    Serialized Form
    • Field Detail

      • genFileName

        public java.lang.String genFileName
      • buildSrcDir

        public java.lang.String buildSrcDir
      • verbose

        public static boolean verbose
      • numLines

        public int numLines
      • currentStatement

        public transient java.lang.String currentStatement
        When calling Statement.addToLineIndex with a parse-node that's being formatted and separately added to the file (as in JS code-gen) this is used to store the statement we are currently formatting so we can compute the relative line number of each statement underneath a compound statement, to add it to the known line number of the generated file
    • Constructor Detail

      • GenFileLineIndex

        public GenFileLineIndex​(java.lang.String genFileName)
        Use this constructor when you generated the line number directly in Java code - i.e. you are generating the code line-by-line like for Js like we do in the JSTypeTemplate conversion.
      • GenFileLineIndex

        public GenFileLineIndex​(java.lang.String genFileName,
                                java.lang.String genFileContents,
                                java.lang.String buildSrcDir)
        Use this constructor for the use case where generated files are created through 'transform' - i.e. we use offsets into the generated file to determine the line number.
    • Method Detail

      • saveLineIndexFile

        public void saveLineIndexFile​(java.io.File lineIndexFile)
      • readFileLineIndexFile

        public static GenFileLineIndex readFileLineIndexFile​(java.lang.String srcName)
      • addMapping

        public void addMapping​(SrcEntry srcFile,
                               int genStart,
                               int genEnd,
                               int srcStart,
                               int srcEnd)
      • getGenLinesForSrcLine

        public java.util.List<java.lang.Integer> getGenLinesForSrcLine​(java.lang.String absFileName,
                                                                       int lineNum)
        Returns the list of line numbers in the generated source file for the source file specified at the given source file line number.
      • getSrcFileForGenLine

        public FileRangeRef getSrcFileForGenLine​(int lineNum)
        Returns the src file name and line number for the generated file's offset
      • cleanUp

        public void cleanUp()
      • dump

        public java.lang.String dump​(int min,
                                     int max)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toBase64VLQ

        public java.lang.String toBase64VLQ​(int val)
      • getSourceMapping

        public java.lang.String getSourceMapping()
      • getSourceMappingJSON

        public java.lang.String getSourceMappingJSON()
      • clone

        public GenFileLineIndex clone()
        Overrides:
        clone in class java.lang.Object
      • getLineIndexFileName

        public static java.lang.String getLineIndexFileName​(java.lang.String genSrcName)
      • getLineIndexFile

        public static java.io.File getLineIndexFile​(java.lang.String genSrcName)