Record Class SourceLocation

java.lang.Object
java.lang.Record
ca.mcscert.jpipe.model.SourceLocation

public record SourceLocation(String source, int line, int column) extends Record
Immutable source position at which a named element was declared.

Line is 1-based (ANTLR convention); column is 0-based. The sentinel UNKNOWN (line = 0) is used when no position is available — ANTLR lines start at 1, so 0 is a safe sentinel that never conflicts with a real location.

The optional source field names the file (or unit) the location belongs to. It is null when the source is not tracked (e.g. in tests or for programmatically created locations). When the load mechanism assembles units from multiple files each location will carry its own source path, making cross-file error messages unambiguous.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final SourceLocation
    Sentinel for "no location known".
  • Constructor Summary

    Constructors
    Constructor
    Description
    SourceLocation(int line, int column)
    Convenience constructor for location without a source file reference.
    SourceLocation(String source, int line, int column)
    Creates an instance of a SourceLocation record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the column record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    True only when a real source position is stored.
    int
    Returns the value of the line record component.
    Returns the value of the source record component.
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • UNKNOWN

      public static final SourceLocation UNKNOWN
      Sentinel for "no location known".
  • Constructor Details

    • SourceLocation

      public SourceLocation(int line, int column)
      Convenience constructor for location without a source file reference.
    • SourceLocation

      public SourceLocation(String source, int line, int column)
      Creates an instance of a SourceLocation record class.
      Parameters:
      source - the value for the source record component
      line - the value for the line record component
      column - the value for the column record component
  • Method Details

    • isKnown

      public boolean isKnown()
      True only when a real source position is stored.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • source

      public String source()
      Returns the value of the source record component.
      Returns:
      the value of the source record component
    • line

      public int line()
      Returns the value of the line record component.
      Returns:
      the value of the line record component
    • column

      public int column()
      Returns the value of the column record component.
      Returns:
      the value of the column record component