Class FileLocation
- java.lang.Object
-
- net.sourceforge.pmd.lang.document.FileLocation
-
public final class FileLocation extends Object
Represents the coordinates of a text region, used for reporting. This provides access to the line and column positions, as well as the text file. Instances can be obtained from aTextRegion
withTextDocument::toLocation
.This should replace the text coordinates methods in
Node
,GenericToken
, andRuleViolation
at least (seeReportable
).
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<FileLocation>
COMPARATOR
static Comparator<FileLocation>
COORDS_COMPARATOR
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FileLocation
caret(FileId fileName, int line, int column)
Returns a new location that starts and ends at the same position.int
getEndColumn()
Exclusive, 1-based column number.int
getEndLine()
Inclusive, 1-based line number.TextPos2d
getEndPos()
Returns the end position.FileId
getFileId()
File name of this position.int
getLineCount()
@Nullable TextRegion
getRegionInFile()
Returns the region in the file, or null if this was not available.int
getStartColumn()
Inclusive, 1-based column number.int
getStartLine()
Inclusive, 1-based line number.TextPos2d
getStartPos()
Returns the start position.static FileLocation
range(FileId fileName, TextRange2d range2d)
Creates a new location for a range of text.String
startPosToString()
Formats the start position as e.g.String
startPosToStringWithFile()
Formats the start position as e.g.TextRange2d
toRange2d()
Turn this into a range country.String
toString()
-
-
-
Field Detail
-
COORDS_COMPARATOR
public static final Comparator<FileLocation> COORDS_COMPARATOR
-
COMPARATOR
public static final Comparator<FileLocation> COMPARATOR
-
-
Method Detail
-
getFileId
public FileId getFileId()
File name of this position.
-
getStartLine
public int getStartLine()
Inclusive, 1-based line number.
-
getEndLine
public int getEndLine()
Inclusive, 1-based line number.
-
getStartColumn
public int getStartColumn()
Inclusive, 1-based column number.
-
getEndColumn
public int getEndColumn()
Exclusive, 1-based column number.
-
getStartPos
public TextPos2d getStartPos()
Returns the start position.
-
getEndPos
public TextPos2d getEndPos()
Returns the end position.
-
toRange2d
public TextRange2d toRange2d()
Turn this into a range country.
-
getRegionInFile
public @Nullable TextRegion getRegionInFile()
Returns the region in the file, or null if this was not available.
-
startPosToString
public String startPosToString()
Formats the start position as e.g."line 1, column 2"
.
-
startPosToStringWithFile
public String startPosToStringWithFile()
Formats the start position as e.g."/path/to/file:1:2"
.
-
getLineCount
public int getLineCount()
-
range
public static FileLocation range(FileId fileName, TextRange2d range2d)
Creates a new location for a range of text.- Throws:
IllegalArgumentException
- If the file name is nullIllegalArgumentException
- If any of the line/col parameters are strictly less than 1IllegalArgumentException
- If the line and column are not correctly orderedIllegalArgumentException
- If the start offset or length are negative
-
caret
public static FileLocation caret(FileId fileName, int line, int column)
Returns a new location that starts and ends at the same position.- Parameters:
fileName
- File nameline
- Line numbercolumn
- Column number- Returns:
- A new location
- Throws:
IllegalArgumentException
- Seerange(FileId, TextRange2d)
-
-