Class LexicalPosition<F>

java.lang.Object
com.io7m.jlexing.core.LexicalPosition<F>
Type Parameters:
F - The type of file information
All Implemented Interfaces:
LexicalPositionType<F>

public final class LexicalPosition<F> extends Object implements LexicalPositionType<F>
The type of lexical positions.
  • Method Details

    • line

      public int line()
      Specified by:
      line in interface LexicalPositionType<F>
      Returns:
      The line number
    • column

      public int column()
      Specified by:
      column in interface LexicalPositionType<F>
      Returns:
      The column number
    • file

      public Optional<F> file()
      Specified by:
      file in interface LexicalPositionType<F>
      Returns:
      The file, if any
    • columnEnd

      public int columnEnd()
      The "end" column number. This defines an inclusive span [column, columnEnd] and defaults to column if not specified.
      Specified by:
      columnEnd in interface LexicalPositionType<F>
      Returns:
      The column end number
      Since:
      3.1.0
    • withLine

      public final LexicalPosition<F> withLine(int value)
      Copy the current immutable object by setting a value for the line attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for line
      Returns:
      A modified copy of the this object
    • withColumn

      public final LexicalPosition<F> withColumn(int value)
      Copy the current immutable object by setting a value for the column attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for column
      Returns:
      A modified copy of the this object
    • withFile

      public final LexicalPosition<F> withFile(F value)
      Copy the current immutable object by setting a present value for the optional file attribute.
      Parameters:
      value - The value for file
      Returns:
      A modified copy of this object
    • withFile

      public final LexicalPosition<F> withFile(Optional<? extends F> optional)
      Copy the current immutable object by setting an optional value for the file attribute. A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning this.
      Parameters:
      optional - A value for file
      Returns:
      A modified copy of this object
    • withColumnEnd

      public final LexicalPosition<F> withColumnEnd(int value)
      Copy the current immutable object by setting a value for the columnEnd attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for columnEnd
      Returns:
      A modified copy of the this object
    • equals

      public boolean equals(Object another)
      This instance is equal to all instances of LexicalPosition that have equal attribute values.
      Overrides:
      equals in class Object
      Returns:
      true if this is equal to another instance
    • hashCode

      public int hashCode()
      Computes a hash code from attributes: line, column, file, columnEnd.
      Overrides:
      hashCode in class Object
      Returns:
      hashCode value
    • toString

      public String toString()
      Prints the immutable value LexicalPosition with attribute values.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the value
    • of

      public static <F> LexicalPosition<F> of(int line, int column, Optional<? extends F> file)
      Construct a new immutable LexicalPosition instance.
      Parameters:
      line - The value for the line attribute
      column - The value for the column attribute
      file - The value for the file attribute
      Returns:
      An immutable LexicalPosition instance
    • copyOf

      public static <F> LexicalPosition<F> copyOf(LexicalPositionType<F> instance)
      Creates an immutable copy of a LexicalPositionType value. Uses accessors to get values to initialize the new immutable instance. If an instance is already immutable, it is returned as is.
      Type Parameters:
      F - generic parameter F
      Parameters:
      instance - The instance to copy
      Returns:
      A copied immutable LexicalPosition instance
    • builder

      public static <F> LexicalPosition.Builder<F> builder()
      Creates a builder for LexicalPosition.
      Type Parameters:
      F - generic parameter F
      Returns:
      A new LexicalPosition builder