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
ConstructorsConstructorDescriptionDocLineComparator(IDocument document, IRegion region, boolean ignoreWhiteSpace) Creates aDocLineComparatorfor the given document range.DocLineComparator(IDocument document, IRegion region, boolean ignoreWhiteSpace, ICompareFilter[] compareFilters, char contributor, Optional<IIgnoreWhitespaceContributor> ignoreWhitespaceContributor) Creates aDocLineComparatorfor the given document range. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of lines in the document.intgetTokenLength(int line) Returns the character length of the token with the given index.intgetTokenStart(int line) Returns the start character position of the token with the given index.booleanrangesEqual(int thisIndex, IRangeComparator otherComparator, int otherIndex) Returnstrueif a line given by the first index matches a line specified by the otherIRangeComparatorand index.booleanskipRangeComparison(int length, int maxLength, IRangeComparator other) Aborts the comparison if the number of tokens is too large.
-
Constructor Details
-
DocLineComparator
Creates aDocLineComparatorfor 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-nullonly lines within this range are takenignoreWhiteSpace- iftruewhite space is ignored when comparing lines
-
DocLineComparator
public DocLineComparator(IDocument document, IRegion region, boolean ignoreWhiteSpace, ICompareFilter[] compareFilters, char contributor, Optional<IIgnoreWhitespaceContributor> ignoreWhitespaceContributor) Creates aDocLineComparatorfor 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-nullonly lines within this range are takenignoreWhiteSpace- iftruewhite space is ignored when comparing linescompareFilters- the active compare filters for the comparecontributor- contributor of documentignoreWhitespaceContributor- contributor for ignore whitespace logic, empty optional allowed, butnullis not allowed
-
-
Method Details
-
getRangeCount
public int getRangeCount()Returns the number of lines in the document.- Specified by:
getRangeCountin interfaceIRangeComparator- Returns:
- number of lines
-
getTokenStart
public int getTokenStart(int line) Description copied from interface:ITokenComparatorReturns 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:
getTokenStartin 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:ITokenComparatorReturns 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:
getTokenLengthin 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
Returnstrueif a line given by the first index matches a line specified by the otherIRangeComparatorand index.- Specified by:
rangesEqualin 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:
trueif the lines are equal
-
skipRangeComparison
Aborts the comparison if the number of tokens is too large.- Specified by:
skipRangeComparisonin interfaceIRangeComparator- Parameters:
length- a number on which to base the decision whether to returntrueorfalsemaxLength- another number on which to base the decision whether to returntrueorfalseother- the otherIRangeComparatorto compare with- Returns:
trueto avoid a too lengthy range comparison
-