@ParametersAreNonnullByDefault public final class SourceLocation extends Object implements Comparable<SourceLocation>
| Modifier and Type | Class and Description |
|---|---|
static class |
SourceLocation.Point
A Point in a source file.
|
| Modifier and Type | Field and Description |
|---|---|
static SourceLocation |
UNKNOWN
A nullish source location.
|
| Constructor and Description |
|---|
SourceLocation(String filePath) |
SourceLocation(String filePath,
int beginLine,
int beginColumn,
int endLine,
int endColumn) |
SourceLocation(String filePath,
SourceLocation.Point begin,
SourceLocation.Point end) |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(SourceLocation o) |
boolean |
equals(Object o) |
SourceLocation |
extend(int lines,
int cols)
Returns a new SourceLocation that starts where this SourceLocation starts and ends
lines and cols further than where it ends. |
SourceLocation |
extend(SourceLocation other)
Returns a new SourceLocation that starts where this SourceLocation starts and ends where
other ends. |
int |
getBeginColumn()
Returns the column number in the source file where this location begins (1-based).
|
int |
getBeginLine()
Returns the line number in the source file where this location begins (1-based).
|
SourceLocation |
getBeginLocation()
Returns a new location that points to the first character of this location.
|
SourceLocation.Point |
getBeginPoint() |
int |
getEndColumn()
Returns the column number in the source file where this location ends (1-based).
|
int |
getEndLine()
Returns the line number in the source file where this location ends (1-based).
|
SourceLocation |
getEndLocation()
Returns a new location that points to the last character of this location.
|
SourceLocation.Point |
getEndPoint() |
String |
getFileName() |
String |
getFilePath()
Returns a file path or URI useful for error messages.
|
int |
hashCode() |
boolean |
isJustBefore(SourceLocation that)
Returns true if this location ends one character before the other location starts.
|
boolean |
isKnown()
True iff this location is known, i.e.
|
SourceLocation |
offsetEndCol(int offset) |
SourceLocation |
offsetStartCol(int offset) |
String |
toString() |
public static final SourceLocation UNKNOWN
This is useful for default initialization of field values or when dealing with situations when you may or may not have a location. Obviously, associating real locations is always preferred when possible.
public SourceLocation(String filePath, int beginLine, int beginColumn, int endLine, int endColumn)
filePath - A file path or URI useful for error messages.beginLine - The line number in the source file where this location begins (1-based), or -1
if associated with the entire file instead of a line.beginColumn - The column number in the source file where this location begins (1-based),
or -1 if associated with the entire file instead of a line.endLine - The line number in the source file where this location ends (1-based), or -1 if
associated with the entire file instead of a line.endColumn - The column number in the source file where this location ends (1-based), or -1
if associated with the entire file instead of a line.public SourceLocation(String filePath)
public SourceLocation(String filePath, SourceLocation.Point begin, SourceLocation.Point end)
@Nonnull public String getFilePath()
public int getBeginLine()
public int getBeginColumn()
public int getEndLine()
public int getEndColumn()
public boolean isJustBefore(SourceLocation that)
public boolean isKnown()
UNKNOWN.public int compareTo(SourceLocation o)
compareTo in interface Comparable<SourceLocation>public SourceLocation offsetStartCol(int offset)
public SourceLocation offsetEndCol(int offset)
public SourceLocation extend(SourceLocation other)
other ends.public SourceLocation extend(int lines, int cols)
lines and cols further than where it ends.public SourceLocation getBeginLocation()
public SourceLocation.Point getBeginPoint()
public SourceLocation getEndLocation()
public SourceLocation.Point getEndPoint()