Class SourcePosition

  • All Implemented Interfaces:
    java.io.Serializable

    @Immutable
    public final class SourcePosition
    extends java.lang.Object
    implements java.io.Serializable
    An immutable position in a text file, used in errors to point the user to an issue.

    Positions that are unknown are represented by -1.

    See Also:
    Serialized Form
    • Constructor Detail

      • SourcePosition

        public SourcePosition​(int startLine,
                              int startColumn,
                              int startOffset,
                              int endLine,
                              int endColumn,
                              int endOffset)
      • SourcePosition

        public SourcePosition​(int lineNumber,
                              int column,
                              int offset)
    • Method Detail

      • toString

        public java.lang.String toString()
        Outputs positions as human-readable formatted strings. e.g.
        84
         84-86
         84:5
         84:5-28
         85:5-86:47
        Overrides:
        toString in class java.lang.Object
        Returns:
        a human readable position.
      • fromString

        public static SourcePosition fromString​(java.lang.String string)
        Given the human-readable formatted string, returns a source position object.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getStartLine

        public int getStartLine()
      • getStartColumn

        public int getStartColumn()
      • getStartOffset

        public int getStartOffset()
      • getEndLine

        public int getEndLine()
      • getEndColumn

        public int getEndColumn()
      • getEndOffset

        public int getEndOffset()
      • compareStart

        public int compareStart​(@NonNull
                                SourcePosition other)
        Compares the start of this SourcePosition with another.
        Returns:
        0 if they are the same, < 0 if this < other and > 0 if this > other
      • compareEnd

        public int compareEnd​(@NonNull
                              SourcePosition other)
        Compares the end of this SourcePosition with another.
        Returns:
        0 if they are the same, < 0 if this < other and > 0 if this > other