Class FileLocation


  • public final class FileLocation
    extends Object
    Represents the coordinates of a text region, used for reporting. This provides access to the line and column positions, as well as the text file. Instances can be obtained from a TextRegion with TextDocument::toLocation.

    This should replace the text coordinates methods in Node, GenericToken, and RuleViolation at least (see Reportable). TODO the end line/end column are barely used, mostly ignored even by renderers. Maybe these could be optional, or replaced by just a length in case a renderer wants to cut out a piece of the file.

    • Method Detail

      • getFileName

        public String getFileName()
        File name of this position. This is a display name, it shouldn't be parsed as a Path.
      • getStartLine

        public int getStartLine()
        Inclusive, 1-based line number.
      • getEndLine

        public int getEndLine()
        Inclusive, 1-based line number.
      • getStartColumn

        public int getStartColumn()
        Inclusive, 1-based column number.
      • getEndColumn

        public int getEndColumn()
        Exclusive, 1-based column number.
      • getStartPos

        public TextPos2d getStartPos()
        Returns the start position.
      • getEndPos

        public TextPos2d getEndPos()
        Returns the end position.
      • toRange2d

        public TextRange2d toRange2d()
        Turn this into a range country.
      • getRegionInFile

        public @Nullable TextRegion getRegionInFile()
        Returns the region in the file, or null if this was not available.
      • startPosToString

        public String startPosToString()
        Formats the start position as e.g. "line 1, column 2".
      • startPosToStringWithFile

        public String startPosToStringWithFile()
        Formats the start position as e.g. "/path/to/file:1:2".
      • caret

        public static FileLocation caret​(String fileName,
                                         int line,
                                         int column)
        Returns a new location that starts and ends at the same position.
        Parameters:
        fileName - File name
        line - Line number
        column - Column number
        Returns:
        A new location
        Throws:
        IllegalArgumentException - See #range(String, int, int, int, int)