Package com.github.javaparser
Class Position
java.lang.Object
com.github.javaparser.Position
- All Implemented Interfaces:
Comparable<Position>
A position in a source file. Lines and columns start counting at 1.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
Line numbers must be positive, thusstatic int
int
static int
The first column -- note that it is 1-indexed (i.e.static int
The first line -- note that it is 1-indexed (i.e.static Position
The first position in the file.int
-
Constructor Summary
ConstructorsConstructorDescriptionPosition(int line, int column)
TODO: Do we refer to the characters as columns, ...or the spaces between (thus also before/after) characters as columns? -
Method Summary
Modifier and TypeMethodDescriptionint
boolean
int
hashCode()
boolean
invalid()
boolean
boolean
isAfterOrEqual(Position otherPosition)
boolean
boolean
isBeforeOrEqual(Position otherPosition)
nextLine()
orIfInvalid(Position alternativePosition)
static Position
pos(int line, int column)
Deprecated.Use the constructor (e.g.right(int characters)
toString()
boolean
valid()
Check if the position is usable.withColumn(int column)
withLine(int line)
-
Field Details
-
line
public final int line -
column
public final int column -
FIRST_LINE
public static final int FIRST_LINEThe first line -- note that it is 1-indexed (i.e. the first line is line 1, as opposed to 0)- See Also:
- Constant Field Values
-
FIRST_COLUMN
public static final int FIRST_COLUMNThe first column -- note that it is 1-indexed (i.e. the first column is column 1, as opposed to 0)- See Also:
- Constant Field Values
-
HOME
The first position in the file. -
ABSOLUTE_BEGIN_LINE
public static final int ABSOLUTE_BEGIN_LINELine numbers must be positive, thus- See Also:
- Constant Field Values
-
ABSOLUTE_END_LINE
public static final int ABSOLUTE_END_LINE- See Also:
- Constant Field Values
-
-
Constructor Details
-
Position
public Position(int line, int column)TODO: Do we refer to the characters as columns, ...or the spaces between (thus also before/after) characters as columns?
-
-
Method Details
-
pos
Deprecated.Use the constructor (e.g.new Position(line, column)
)Convenient factory method. -
withColumn
- Returns:
- Jump to the given column number, while retaining the current line number.
-
withLine
- Returns:
- Jump to the given line number, while retaining the current column number.
-
right
- Returns:
- a position that is "characters" characters more to the right than this position.
-
nextLine
- Returns:
- a position that is on the start of the next line from this position.
-
valid
public boolean valid()Check if the position is usable. Does not know what it is pointing at, so it can't check if the position is after the end of the source. -
invalid
public boolean invalid() -
orIfInvalid
- Returns:
- If this position is valid, this. Otherwise, if the alternativePosition is valid, return that. Otherwise otherwise, just return this. TODO: Simplify/clarify.
-
isAfter
-
isAfterOrEqual
-
isBefore
-
isBeforeOrEqual
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Position>
-
equals
-
hashCode
public int hashCode() -
toString
-