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 aTextRegionwithTextDocument::toLocation.This should replace the text coordinates methods in
Node,GenericToken, andRuleViolationat least (seeReportable).
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<FileLocation>COMPARATORstatic Comparator<FileLocation>COORDS_COMPARATOR
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FileLocationcaret(FileId fileName, int line, int column)Returns a new location that starts and ends at the same position.intgetEndColumn()Exclusive, 1-based column number.intgetEndLine()Inclusive, 1-based line number.TextPos2dgetEndPos()Returns the end position.FileIdgetFileId()File name of this position.intgetLineCount()@Nullable TextRegiongetRegionInFile()Returns the region in the file, or null if this was not available.intgetStartColumn()Inclusive, 1-based column number.intgetStartLine()Inclusive, 1-based line number.TextPos2dgetStartPos()Returns the start position.static FileLocationrange(FileId fileName, TextRange2d range2d)Creates a new location for a range of text.StringstartPosToString()Formats the start position as e.g.StringstartPosToStringWithFile()Formats the start position as e.g.TextRange2dtoRange2d()Turn this into a range country.StringtoString()
-
-
-
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)
-
-