Package org.eclipse.compare.internal
Class DocLineComparator
java.lang.Object
org.eclipse.compare.internal.DocLineComparator
- All Implemented Interfaces:
ITokenComparator
,IRangeComparator
Implements the
IRangeComparator
interface for lines in a document.
A DocLineComparator
is used as the input for the RangeDifferencer
engine to perform a line oriented compare on documents.
A DocLineComparator
doesn't know anything about line separators because
its notion of lines is solely defined in the underlying IDocument
.
-
Constructor Summary
ConstructorDescriptionDocLineComparator
(IDocument document, IRegion region, boolean ignoreWhiteSpace) Creates aDocLineComparator
for the given document range.DocLineComparator
(IDocument document, IRegion region, boolean ignoreWhiteSpace, ICompareFilter[] compareFilters, char contributor, Optional<IIgnoreWhitespaceContributor> ignoreWhitespaceContributor) Creates aDocLineComparator
for the given document range. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the number of lines in the document.int
getTokenLength
(int line) Returns the character length of the token with the given index.int
getTokenStart
(int line) Returns the start character position of the token with the given index.boolean
rangesEqual
(int thisIndex, IRangeComparator otherComparator, int otherIndex) Returnstrue
if a line given by the first index matches a line specified by the otherIRangeComparator
and index.boolean
skipRangeComparison
(int length, int maxLength, IRangeComparator other) Aborts the comparison if the number of tokens is too large.
-
Constructor Details
-
DocLineComparator
Creates aDocLineComparator
for the given document range. ignoreWhiteSpace controls whether comparing lines (in methodrangesEqual
) should ignore whitespace.- Parameters:
document
- the document from which the lines are takenregion
- if non-null
only lines within this range are takenignoreWhiteSpace
- iftrue
white space is ignored when comparing lines
-
DocLineComparator
public DocLineComparator(IDocument document, IRegion region, boolean ignoreWhiteSpace, ICompareFilter[] compareFilters, char contributor, Optional<IIgnoreWhitespaceContributor> ignoreWhitespaceContributor) Creates aDocLineComparator
for the given document range. ignoreWhiteSpace controls whether comparing lines (in methodrangesEqual
) should ignore whitespace. Compare filters may be used to affect the detection of line differences.- Parameters:
document
- the document from which the lines are takenregion
- if non-null
only lines within this range are takenignoreWhiteSpace
- iftrue
white space is ignored when comparing linescompareFilters
- the active compare filters for the comparecontributor
- contributor of documentignoreWhitespaceContributor
- contributor for ignore whitespace logic, empty optional allowed, butnull
is not allowed
-
-
Method Details
-
getRangeCount
public int getRangeCount()Returns the number of lines in the document.- Specified by:
getRangeCount
in interfaceIRangeComparator
- Returns:
- number of lines
-
getTokenStart
public int getTokenStart(int line) Description copied from interface:ITokenComparator
Returns the start character position of the token with the given index. If the index is out of range (but not negative) the character position behind the last character (the length of the input string) is returned.- Specified by:
getTokenStart
in interfaceITokenComparator
- Parameters:
line
- index of the token for which to return the start position- Returns:
- the start position of the token with the given index
-
getTokenLength
public int getTokenLength(int line) Description copied from interface:ITokenComparator
Returns the character length of the token with the given index. If the index is out of range (but not negative) the value 0 is returned.- Specified by:
getTokenLength
in interfaceITokenComparator
- Parameters:
line
- index of the token for which to return the start position- Returns:
- the character length of the token with the given index
-
rangesEqual
Returnstrue
if a line given by the first index matches a line specified by the otherIRangeComparator
and index.- Specified by:
rangesEqual
in interfaceIRangeComparator
- Parameters:
thisIndex
- the number of the line within this range comparatorotherComparator
- the range comparator to compare this withotherIndex
- the number of the line within the other comparator- Returns:
true
if the lines are equal
-
skipRangeComparison
Aborts the comparison if the number of tokens is too large.- Specified by:
skipRangeComparison
in interfaceIRangeComparator
- Parameters:
length
- a number on which to base the decision whether to returntrue
orfalse
maxLength
- another number on which to base the decision whether to returntrue
orfalse
other
- the otherIRangeComparator
to compare with- Returns:
true
to avoid a too lengthy range comparison
-