Package org.eclipse.jface.text
Class AbstractLineTracker
java.lang.Object
org.eclipse.jface.text.AbstractLineTracker
- All Implemented Interfaces:
ILineTracker
,ILineTrackerExtension
- Direct Known Subclasses:
ConfigurableLineTracker
,DefaultLineTracker
public abstract class AbstractLineTracker
extends Object
implements ILineTracker, ILineTrackerExtension
Abstract implementation of
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:
- "" -> [0,0]
- "a" -> [0,1]
- "\n" -> [0,1], [1,0]
- "a\n" -> [0,2], [2,0]
- "a\nb" -> [0,2], [2,1]
- "a\nbc\n" -> [0,2], [2,3], [5,0]
This class must be subclassed.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Combines the information of the occurrence of a line delimiter.protected static class
Representation of replace and set requests. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final void
Checks the presence of a rewrite session and flushes it.int
computeNumberOfLines
(String text) Computes the number of lines in the given text.protected final void
Flushes the active rewrite session.getLineDelimiter
(int line) Returns the line delimiter of the specified line.getLineInformation
(int line) Returns a line description of the given 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
Returns the number of lines.int
getNumberOfLines
(int offset, int length) Returns the number of lines which are occupied by a given text range.protected final boolean
Tells whether there's an active rewrite session.protected abstract AbstractLineTracker.DelimiterInfo
nextDelimiterInfo
(String text, int offset) Returns the information about the first delimiter found in the given text starting at the given offset.void
Informs the line tracker about the specified change in the tracked text.void
Sets the tracked text to the specified text.final void
Tells the line tracker that a rewrite session started.final void
stopRewriteSession
(DocumentRewriteSession session, String text) Tells the line tracker that the rewrite session has finished.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.jface.text.ILineTracker
getLegalLineDelimiters
-
Constructor Details
-
AbstractLineTracker
protected AbstractLineTracker()Creates a new line tracker.
-
-
Method Details
-
computeNumberOfLines
Description copied from interface:ILineTracker
Computes the number of lines in the given text.- Specified by:
computeNumberOfLines
in interfaceILineTracker
- Parameters:
text
- the text whose number of lines should be computed- Returns:
- the number of lines in the given text
-
getLineDelimiter
Description copied from interface:ILineTracker
Returns the line delimiter of the specified line. Returnsnull
if the line is not closed with a line delimiter.- Specified by:
getLineDelimiter
in interfaceILineTracker
- Parameters:
line
- the line whose line delimiter is queried- Returns:
- the line's delimiter or
null
if line does not have a delimiter - Throws:
BadLocationException
- if the line number is invalid in this tracker's line structure
-
getLineInformation
Description copied from interface:ILineTracker
Returns a line description of the given line. The description contains the start offset and the length of the line excluding the line's delimiter.- Specified by:
getLineInformation
in interfaceILineTracker
- Parameters:
line
- the line that should be described- Returns:
- a region describing the line
- Throws:
BadLocationException
- if line is unknown to this tracker
-
getLineInformationOfOffset
Description copied from interface:ILineTracker
Returns a line description of the line at the given offset. The description contains the start offset and the length of the line excluding the line's delimiter.- Specified by:
getLineInformationOfOffset
in interfaceILineTracker
- Parameters:
offset
- the offset whose line should be described- Returns:
- a region describing the line
- Throws:
BadLocationException
- if offset is invalid in this tracker
-
getLineLength
Description copied from interface:ILineTracker
Returns length of the specified line including the line's delimiter.- Specified by:
getLineLength
in interfaceILineTracker
- Parameters:
line
- the line of interest- Returns:
- the length of the line
- Throws:
BadLocationException
- if line is unknown to this tracker
-
getLineNumberOfOffset
Description copied from interface:ILineTracker
Returns the line number the character at the given offset belongs to.- Specified by:
getLineNumberOfOffset
in interfaceILineTracker
- Parameters:
offset
- the offset whose line number to be determined- Returns:
- the number of the line the offset is on
- Throws:
BadLocationException
- if the offset is invalid in this tracker
-
getLineOffset
Description copied from interface:ILineTracker
Returns the position of the first character of the specified line.- Specified by:
getLineOffset
in interfaceILineTracker
- Parameters:
line
- the line of interest- Returns:
- offset of the first character of the line
- Throws:
BadLocationException
- if the line is unknown to this tracker
-
getNumberOfLines
public int getNumberOfLines()Description copied from interface:ILineTracker
Returns the number of lines.Note that a document always has at least one line.
- Specified by:
getNumberOfLines
in interfaceILineTracker
- Returns:
- the number of lines in this tracker's line structure
-
getNumberOfLines
Description copied from interface:ILineTracker
Returns the number of lines which are occupied by a given text range.- Specified by:
getNumberOfLines
in interfaceILineTracker
- Parameters:
offset
- the offset of the specified text rangelength
- the length of the specified text range- Returns:
- the number of lines occupied by the specified range
- Throws:
BadLocationException
- if specified range is unknown to this tracker
-
set
Description copied from interface:ILineTracker
Sets the tracked text to the specified text.- Specified by:
set
in interfaceILineTracker
- Parameters:
text
- the new tracked text
-
replace
Description copied from interface:ILineTracker
Informs the line tracker about the specified change in the tracked text.- Specified by:
replace
in interfaceILineTracker
- Parameters:
offset
- the offset of the replaced textlength
- the length of the replaced texttext
- the substitution text- Throws:
BadLocationException
- if specified range is unknown to this tracker
-
nextDelimiterInfo
Returns the information about the first delimiter found in the given text starting at the given offset.- Parameters:
text
- the text to be searchedoffset
- the offset in the given text- Returns:
- the information of the first found delimiter or
null
-
startRewriteSession
Description copied from interface:ILineTrackerExtension
Tells the line tracker that a rewrite session started. A rewrite session is a sequence of replace operations that form a semantic unit. The line tracker is allowed to use that information for internal optimization.- Specified by:
startRewriteSession
in interfaceILineTrackerExtension
- Parameters:
session
- the rewrite session
-
stopRewriteSession
Description copied from interface:ILineTrackerExtension
Tells the line tracker that the rewrite session has finished. This method is only called whenstartRewriteSession
has been called before. The text resulting from the rewrite session is passed to the line tracker.- Specified by:
stopRewriteSession
in interfaceILineTrackerExtension
- Parameters:
session
- the rewrite sessiontext
- the text with which to re-initialize the line tracker
-
hasActiveRewriteSession
protected final boolean hasActiveRewriteSession()Tells whether there's an active rewrite session.- Returns:
true
if there is an active rewrite session,false
otherwise- Since:
- 3.1
-
flushRewriteSession
Flushes the active rewrite session.- Throws:
BadLocationException
- in case the recorded requests cannot be processed correctly- Since:
- 3.1
-
checkRewriteSession
Checks the presence of a rewrite session and flushes it.- Throws:
BadLocationException
- in case flushing does not succeed- Since:
- 3.1
-