Class SourcePosition


  • public final class SourcePosition
    extends Object
    Immutable line/column position in a source file, with an optional character offset.
    • Constructor Detail

      • SourcePosition

        public SourcePosition​(int line,
                              int column,
                              int offset)
        Creates a position.
        Parameters:
        line - the 1-based line
        column - the 1-based column
        offset - the character offset into the source, -1 if unknown
    • Method Detail

      • getLine

        public int getLine()
        Returns:
        the line
      • getColumn

        public int getColumn()
        Returns:
        the column
      • getOffset

        public int getOffset()
        Returns:
        the offset
      • of

        public static SourcePosition of​(int line,
                                        int column)
        Creates a position with no character offset.
        Parameters:
        line - the 1-based line
        column - the 1-based column
        Returns:
        the position, with offset -1
      • of

        public static SourcePosition of​(int line,
                                        int column,
                                        int offset)
        Creates a position with a known character offset.
        Parameters:
        line - the 1-based line
        column - the 1-based column
        offset - the character offset into the source
        Returns:
        the position
      • withOffset

        public SourcePosition withOffset​(int newOffset)
        Copies this position with a different character offset.
        Parameters:
        newOffset - the offset to use
        Returns:
        the new position
      • isUnknown

        public boolean isUnknown()
        Returns:
        true when neither line nor column is set
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object