Package nz.org.riskscape.dsl
Class SourceLocation
java.lang.Object
nz.org.riskscape.dsl.SourceLocation
- All Implemented Interfaces:
Comparable<SourceLocation>
Information about a specific character location within a string of source code
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSourceLocation(int index, int line, int column) Creates a newSourceLocationinstance. -
Method Summary
Modifier and TypeMethodDescriptionCreates that extends/modifies the given URI so that it includes an anchor fragment that points to this source code locationadvance(int moveByChars) protected booleanintcompareTo(SourceLocation rhs) booleanintColumn number within the current line (1 based)intgetIndex()Absolute index in to the source string.intgetLine()Line number (1 based)inthashCode()static SourceLocationindex(int index) booleannewline()static Optional<SourceLocation>parseUriFragment(String fragment) Attempt to parse the given URI fragment and turn it in to aSourceLocation, returning empty if it doesn't parse.toString()Creates a string that can be embedded in a URI as an anchor fragment, seeparseUriFragment(String)for the inverse method.static SourceLocationunlined(int index)
-
Field Details
-
START
Starting position.
-
-
Constructor Details
-
SourceLocation
public SourceLocation(int index, int line, int column) Creates a new
SourceLocationinstance.- Parameters:
index- Absolute index in to the source string.line- Line number (1 based)column- Column number within the current line (1 based)
-
-
Method Details
-
parseUriFragment
Attempt to parse the given URI fragment and turn it in to a
SourceLocation, returning empty if it doesn't parse. SeetoUriFragment()for the inverse method.- Parameters:
fragment- the anchor fragment part of a URI, can be null, seeURI.getFragment().
-
unlined
- Returns:
- a location in source that has lost track of line numbers.
-
index
- Returns:
- a single lined location at the given index
-
toString
-
advance
- Returns:
- a new SourceLocation shifted forward by moveByChars.
-
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
Creates a string that can be embedded in a URI as an anchor fragment, see
parseUriFragment(String)for the inverse method. -
addToUri
Creates that extends/modifies the given URI so that it includes an anchor fragment that points to this source code location
-
compareTo
- Specified by:
compareToin interfaceComparable<SourceLocation>
-
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
-
canEqual
-
hashCode
public int hashCode()
-