Package com.github.javaparser
Class Position
- java.lang.Object
-
- com.github.javaparser.Position
-
- All Implemented Interfaces:
java.lang.Comparable<Position>
- Direct Known Subclasses:
UnicodeEscapeProcessingProvider.PositionMapping.DeltaInfo
public class Position extends java.lang.Object implements java.lang.Comparable<Position>
A position in a source file. Lines and columns start counting at 1.
-
-
Field Summary
Fields Modifier and Type Field Description static intABSOLUTE_BEGIN_LINELine numbers must be positive, thusstatic intABSOLUTE_END_LINEintcolumnstatic intFIRST_COLUMNThe first column -- note that it is 1-indexed (i.e.static intFIRST_LINEThe first line -- note that it is 1-indexed (i.e.static PositionHOMEThe first position in the file.intline
-
Constructor Summary
Constructors Constructor Description 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 Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intcompareTo(Position otherPosition)booleanequals(java.lang.Object o)inthashCode()booleaninvalid()booleanisAfter(Position otherPosition)booleanisAfterOrEqual(Position otherPosition)booleanisBefore(Position otherPosition)booleanisBeforeOrEqual(Position otherPosition)PositionnextLine()PositionorIfInvalid(Position alternativePosition)static Positionpos(int line, int column)Deprecated.Use the constructor (e.g.Positionright(int characters)java.lang.StringtoString()booleanvalid()Check if the position is usable.PositionwithColumn(int column)PositionwithLine(int line)
-
-
-
Field Detail
-
line
public final int line
-
column
public final int column
-
FIRST_LINE
public static final int FIRST_LINE
The 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_COLUMN
The 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
public static final Position HOME
The first position in the file.
-
ABSOLUTE_BEGIN_LINE
public static final int ABSOLUTE_BEGIN_LINE
Line 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
-
-
Method Detail
-
pos
@Deprecated public static Position pos(int line, int column)
Deprecated.Use the constructor (e.g.new Position(line, column))Convenient factory method.
-
withColumn
public Position withColumn(int column)
- Returns:
- Jump to the given column number, while retaining the current line number.
-
withLine
public Position withLine(int line)
- Returns:
- Jump to the given line number, while retaining the current column number.
-
right
public Position right(int characters)
- Returns:
- a position that is "characters" characters more to the right than this position.
-
nextLine
public 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.
-
orIfInvalid
public Position orIfInvalid(Position alternativePosition)
- Returns:
- If this position is valid, this. Otherwise, if the alternativePosition is valid, return that. Otherwise otherwise, just return this. TODO: Simplify/clarify.
-
isAfter
public boolean isAfter(Position otherPosition)
-
isAfterOrEqual
public boolean isAfterOrEqual(Position otherPosition)
-
isBefore
public boolean isBefore(Position otherPosition)
-
isBeforeOrEqual
public boolean isBeforeOrEqual(Position otherPosition)
-
compareTo
public int compareTo(Position otherPosition)
- Specified by:
compareToin interfacejava.lang.Comparable<Position>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-