Package com.tonic.analysis.source.parser
Class SourcePosition
- java.lang.Object
-
- com.tonic.analysis.source.parser.SourcePosition
-
public final class SourcePosition extends Object
Immutable line/column position in a source file, with an optional character offset.
-
-
Field Summary
Fields Modifier and Type Field Description static SourcePositionUNKNOWN
-
Constructor Summary
Constructors Constructor Description SourcePosition(int line, int column, int offset)Creates a position.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)intgetColumn()intgetLine()intgetOffset()inthashCode()booleanisUnknown()static SourcePositionof(int line, int column)Creates a position with no character offset.static SourcePositionof(int line, int column, int offset)Creates a position with a known character offset.StringtoString()SourcePositionwithOffset(int newOffset)Copies this position with a different character offset.
-
-
-
Field Detail
-
UNKNOWN
public static final SourcePosition UNKNOWN
-
-
Method Detail
-
getLine
public int getLine()
- Returns:
- the line
-
getColumn
public int getColumn()
- Returns:
- the column
-
getOffset
public int getOffset()
- Returns:
- the offset
-
of
public static SourcePosition of(int line, int column)
Creates a position with no character offset.- Parameters:
line- the 1-based linecolumn- the 1-based column- Returns:
- the position, with offset -1
-
of
public static SourcePosition of(int line, int column, int offset)
Creates a position with a known character offset.- Parameters:
line- the 1-based linecolumn- the 1-based columnoffset- the character offset into the source- Returns:
- the position
-
withOffset
public SourcePosition withOffset(int newOffset)
Copies this position with a different character offset.- Parameters:
newOffset- the offset to use- Returns:
- the new position
-
isUnknown
public boolean isUnknown()
- Returns:
- true when neither line nor column is set
-
-