public class LocationAdjuster extends java.lang.Object implements ILineAdjuster
ElementLocation
for text that is slightly modified. The
main use-case is the update of locations where the local (adjusted) text has
different line ending, different content due to keyword expansion, or minor
local modifications compared to the text on which the analysis was executed
(original text).
Both the original and adjusted text may have arbitrary line endings.
The implementation is based on a token diff, which can lead to minor
deviations for offsets that are not aligned with token boundaries. A
character diff would be more precise, but is too performance and memory
intensive for large files.Constructor and Description |
---|
LocationAdjuster(java.lang.String originalText,
java.lang.String adjustedText)
Constructor.
|
LocationAdjuster(java.lang.String originalText,
java.lang.String adjustedText,
java.lang.String adjustedUniformPath)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
LineBasedRegion |
adjustLine(int line,
java.util.Set<java.lang.Integer> invalidLines)
Adjusts the location of a single line.
|
ElementLocation |
adjustLocation(ElementLocation location)
Returns a new location with adjusted offsets (if necessary).
|
TextRegionLocation |
adjustLocation(TextRegionLocation location)
Returns a new location with adjusted offsets (if necessary).
|
Region |
getAdjustedRegion(int originalStartOffset,
int originalEndOffset)
Maps a zero-based offset range (both inclusive) to the adjusted string.
|
int |
getOriginalLineCount()
Returns the line count of the original text
|
public LocationAdjuster(java.lang.String originalText, java.lang.String adjustedText, java.lang.String adjustedUniformPath)
SimpleValidLinesFilter
.originalText
- the text for which the input locations have been created, i.e. the
text from the analysis. May be null
, in which case no
adjustment is performed.adjustedText
- the text for which the locations should be adjusted, i.e. the
local text.adjustedUniformPath
- the adjusted uniform path for adjusted findings.public LocationAdjuster(java.lang.String originalText, java.lang.String adjustedText)
originalText
- the text for which the input locations have been created, i.e. the
text from the analysis.adjustedText
- the text for which the locations should be adjusted, i.e. the
local text.public Region getAdjustedRegion(int originalStartOffset, int originalEndOffset)
null
if the region could not be approximately mapped.public ElementLocation adjustLocation(ElementLocation location)
null
if the location cannot be mapped to the adjusted text.public TextRegionLocation adjustLocation(TextRegionLocation location)
null
if the cannot be mapped to the adjusted text.public LineBasedRegion adjustLine(int line, java.util.Set<java.lang.Integer> invalidLines)
null
is returned.adjustLine
in interface ILineAdjuster
line
- the one-based line number of be adjusted.invalidLines
- used for collecting invalid lines.public int getOriginalLineCount()
getOriginalLineCount
in interface ILineAdjuster