public class TreeLineTracker extends Object implements ILineTracker
ILineTracker
. It lets the definition
of line delimiters to subclasses. Assuming that '\n' is the only line
delimiter, this abstract implementation defines the following line scheme:
This class must be subclassed.
Performance: The query operations perform in O(log n) where n is the number of lines in the document. The modification operations roughly perform in O(l * log n) where n is the number of lines in the document and l is the sum of the number of removed, added or modified lines.
Modifier and Type | Field and Description |
---|---|
static String[] |
DELIMITERS
The predefined delimiters of this tracker
|
Modifier | Constructor and Description |
---|---|
protected |
TreeLineTracker()
Creates a new line tracker.
|
|
TreeLineTracker(org.eclipse.lemminx.commons.ListLineTracker tracker)
Package visible constructor for creating a tree tracker from a list tracker.
|
Modifier and Type | Method and Description |
---|---|
int |
computeNumberOfLines(String text)
Computes the number of lines in the given text.
|
String |
getLineDelimiter(int line)
Returns the line delimiter of the specified line.
|
org.eclipse.lemminx.commons.Line |
getLineInformation(int line)
Returns a line description of the given line.
|
org.eclipse.lemminx.commons.Line |
getLineInformationOfOffset(int offset)
Returns a line description of the line at the given offset.
|
int |
getLineLength(int line)
Returns length of the specified line including the line's delimiter.
|
int |
getLineNumberOfOffset(int offset)
Returns the line number the character at the given offset belongs to.
|
int |
getLineOffset(int line)
Returns the position of the first character of the specified line.
|
int |
getNumberOfLines()
Returns the number of lines.
|
int |
getNumberOfLines(int offset,
int length)
Returns the number of lines which are occupied by a given text range.
|
int |
getOffsetAt(org.eclipse.lsp4j.Position position) |
org.eclipse.lsp4j.Position |
getPositionAt(int offset) |
protected ListLineTracker.DelimiterInfo |
nextDelimiterInfo(String text,
int offset)
Returns the information about the first delimiter found in the given text
starting at the given offset.
|
void |
replace(int offset,
int length,
String text)
Informs the line tracker about the specified change in the tracked text.
|
void |
set(String text)
Sets the tracked text to the specified text.
|
String |
toString() |
public static final String[] DELIMITERS
protected TreeLineTracker()
public TreeLineTracker(org.eclipse.lemminx.commons.ListLineTracker tracker)
tracker
- the list line trackerpublic final void replace(int offset, int length, String text) throws BadLocationException
ILineTracker
replace
in interface ILineTracker
offset
- the offset of the replaced textlength
- the length of the replaced texttext
- the substitution textBadLocationException
- if specified range is unknown to this trackerprotected ListLineTracker.DelimiterInfo nextDelimiterInfo(String text, int offset)
text
- the text to be searchedoffset
- the offset in the given textnull
public final String getLineDelimiter(int line) throws BadLocationException
ILineTracker
null
if the
line is not closed with a line delimiter.getLineDelimiter
in interface ILineTracker
line
- the line whose line delimiter is queriednull
if line does not have a delimiterBadLocationException
- if the line number is invalid in this tracker's line structurepublic final int computeNumberOfLines(String text)
ILineTracker
computeNumberOfLines
in interface ILineTracker
text
- the text whose number of lines should be computedpublic final int getNumberOfLines()
ILineTracker
Note that a document always has at least one line.
getNumberOfLines
in interface ILineTracker
public final int getNumberOfLines(int offset, int length) throws BadLocationException
ILineTracker
getNumberOfLines
in interface ILineTracker
offset
- the offset of the specified text rangelength
- the length of the specified text rangeBadLocationException
- if specified range is unknown to this trackerpublic final int getLineOffset(int line) throws BadLocationException
ILineTracker
getLineOffset
in interface ILineTracker
line
- the line of interestBadLocationException
- if the line is unknown to this trackerpublic final int getLineLength(int line) throws BadLocationException
ILineTracker
getLineLength
in interface ILineTracker
line
- the line of interestBadLocationException
- if line is unknown to this trackerpublic final int getLineNumberOfOffset(int offset) throws BadLocationException
ILineTracker
getLineNumberOfOffset
in interface ILineTracker
offset
- the offset whose line number to be determinedBadLocationException
- if the offset is invalid in this trackerpublic final org.eclipse.lsp4j.Position getPositionAt(int offset) throws BadLocationException
getPositionAt
in interface ILineTracker
BadLocationException
public int getOffsetAt(org.eclipse.lsp4j.Position position) throws BadLocationException
getOffsetAt
in interface ILineTracker
BadLocationException
public final org.eclipse.lemminx.commons.Line getLineInformationOfOffset(int offset) throws BadLocationException
ILineTracker
getLineInformationOfOffset
in interface ILineTracker
offset
- the offset whose line should be describedBadLocationException
- if offset is invalid in this trackerpublic final org.eclipse.lemminx.commons.Line getLineInformation(int line) throws BadLocationException
ILineTracker
getLineInformation
in interface ILineTracker
line
- the line that should be describedBadLocationException
- if line is unknown to this trackerpublic final void set(String text)
ILineTracker
set
in interface ILineTracker
text
- the new tracked textCopyright © 2021. All rights reserved.