Record Class LspPosition

java.lang.Object
java.lang.Record
smile.util.lsp.LspPosition
Record Components:
line - the 1-based line number (first line = 1).
character - the 1-based character offset (first column = 1).

public record LspPosition(int line, int character) extends Record
A 1-based position inside a text document, as displayed in editors.

The LSP specification uses 0-based lines and characters internally. This record stores the editor-friendly 1-based values and provides toLspLine() / toLspCharacter() helpers for conversion.

  • Constructor Summary

    Constructors
    Constructor
    Description
    LspPosition(int line, int character)
    Validates that both coordinates are positive (≥ 1).
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the character record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    fromProtocol(org.eclipse.lsp4j.Position pos)
    Creates an LspPosition from an LSP4J Position (0-based) by adding 1 to both coordinates.
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the line record component.
    int
    Returns the 0-based character offset required by the LSP specification.
    int
    Returns the 0-based line index required by the LSP specification.
    org.eclipse.lsp4j.Position
    Converts this position to the LSP4J Position.
    Returns a string representation of this record class.

    Methods inherited from class Object

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

    • LspPosition

      public LspPosition(int line, int character)
      Validates that both coordinates are positive (≥ 1).
  • Method Details

    • toLspLine

      public int toLspLine()
      Returns the 0-based line index required by the LSP specification.
      Returns:
      line - 1.
    • toLspCharacter

      public int toLspCharacter()
      Returns the 0-based character offset required by the LSP specification.
      Returns:
      character - 1.
    • toProtocol

      public org.eclipse.lsp4j.Position toProtocol()
      Converts this position to the LSP4J Position.
      Returns:
      a new LSP4J Position with 0-based coordinates.
    • fromProtocol

      public static LspPosition fromProtocol(org.eclipse.lsp4j.Position pos)
      Creates an LspPosition from an LSP4J Position (0-based) by adding 1 to both coordinates.
      Parameters:
      pos - the 0-based LSP4J position.
      Returns:
      the equivalent 1-based position.
    • 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. All components in this record class 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.
    • line

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

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