Class SourceLocation

java.lang.Object
nz.org.riskscape.dsl.SourceLocation

public class SourceLocation extends Object

Information about a specific character location within a string of source code

  • Field Details

  • Constructor Details

    • SourceLocation

      public SourceLocation(int index, int line, int column)
  • Method Details

    • parseUriFragment

      public static Optional<SourceLocation> parseUriFragment(String fragment)

      Attempt to parse the given URI fragment and turn it in to a SourceLocation, returning empty if it doesn't parse. See toUriFragment() for the inverse method.

      Parameters:
      fragment - the anchor fragment part of a URI, can be null, see URI.getFragment().
    • unlined

      public static SourceLocation unlined(int index)
      Returns:
      a location in source that has lost track of line numbers.
    • index

      public static SourceLocation index(int index)
      Returns:
      a single lined location at the given index
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • advance

      public SourceLocation advance(int moveByChars)
      Returns:
      a new SourceLocation shifted forward by moveByChars.
    • newline

      public SourceLocation newline()
      Returns:
      a new SourceLocation at the same overall index, but at the start of a new line, i.e. index stays the same, line is incremented and column is set to 1.
    • isUnlined

      public boolean isUnlined()
      Returns:
      true if this source location has lost track of lines
    • toUriFragment

      public String toUriFragment()

      Creates a string that can be embedded in a URI as an anchor fragment, see parseUriFragment(String) for the inverse method.

    • addToUri

      public URI addToUri(URI existing)

      Creates that extends/modifies the given URI so that it includes an anchor fragment that points to this source code location

    • getIndex

      public int getIndex()

      Absolute index in to the source string.

    • getLine

      public int getLine()

      Line number (1 based)

    • getColumn

      public int getColumn()

      Column number within the current line (1 based)

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object