Class FileLocation
java.lang.Object
net.sourceforge.pmd.lang.document.FileLocation
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 a
TextRegion with TextDocument::toLocation.
This should replace the text coordinates methods in Node,
GenericToken, and RuleViolation at least (see Reportable).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<FileLocation> static final Comparator<FileLocation> -
Method Summary
Modifier and TypeMethodDescriptionstatic FileLocationReturns a new location that starts and ends at the same position.intExclusive, 1-based column number.intInclusive, 1-based line number.Returns the end position.File name of this position.int@Nullable TextRegionReturns the region in the file, or null if this was not available.intInclusive, 1-based column number.intInclusive, 1-based line number.Returns the start position.static FileLocationrange(FileId fileName, TextRange2d range2d) Creates a new location for a range of text.Formats the start position as e.g.Formats the start position as e.g.Turn this into a range country.toString()
-
Field Details
-
COORDS_COMPARATOR
-
COMPARATOR
-
-
Method Details
-
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
Returns the start position. -
getEndPos
Returns the end position. -
toRange2d
Turn this into a range country. -
getRegionInFile
Returns the region in the file, or null if this was not available. -
startPosToString
Formats the start position as e.g."line 1, column 2". -
startPosToStringWithFile
Formats the start position as e.g."/path/to/file:1:2". -
getLineCount
public int getLineCount() -
range
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
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)
-
toString
-