org.eclipse.cdt.internal.core
Class PositionTracker

java.lang.Object
  extended by org.eclipse.cdt.internal.core.PositionTracker
All Implemented Interfaces:
IPositionConverter
Direct Known Subclasses:
SimplePositionTracker

public class PositionTracker
extends java.lang.Object
implements IPositionConverter

Tracks changes made to a text buffer, to afterwards recalculate positions.

Author:
markus.schorn@windriver.com

Constructor Summary
PositionTracker()
           
 
Method Summary
 org.eclipse.jface.text.IRegion actualToHistoric(org.eclipse.jface.text.IRegion actualPosition)
          Converts an actual character range to the range where the underlying text was originally found.
 void clear()
          Resets the tracker to a state reflecting no changes.
 int currentOffset(int historicOffset)
          Calculates the position in the modified text.
 void delete(int offset, int count)
          Notifies the tracker of the removal of characters.
 int depth()
          For the purpose of testing.
 int getMemorySize()
           
 long getRetiredTimeStamp()
           
 long getTimeStamp()
           
 int historicOffset(int currentOffset)
          Calculates the position in the original unmodified text.
 org.eclipse.jface.text.IRegion historicToActual(org.eclipse.jface.text.IRegion historicPosition)
          Converts a historic character range to the range where the underlying text currently can be found.
 void insert(int offset, int count)
          Notifies the tracker of the insertion of characters.
 boolean isModified()
           
 void print(java.io.PrintStream out)
          For the purpose of testing.
 void retire(PositionTracker inFavourOf)
          Makes this tracker final.
 void setTimeStamp(long timeStamp)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PositionTracker

public PositionTracker()
Method Detail

clear

public void clear()
Resets the tracker to a state reflecting no changes.


insert

public void insert(int offset,
                   int count)
Notifies the tracker of the insertion of characters. It is assumed that character get inserted before the offset.

Parameters:
offset - offset of the character in front of which insertion occurs.
count - amount of characters inserted.

delete

public void delete(int offset,
                   int count)
Notifies the tracker of the removal of characters. delete(0,1) removes the first character, for convenience delete(1,-1) does the same.

Parameters:
offset - offset of the first character deleted.
count - amount of characters deleted.

historicOffset

public int historicOffset(int currentOffset)
Calculates the position in the original unmodified text.

Parameters:
currentOffset - position in the modified text.
Returns:
position in the unmodified text.

currentOffset

public int currentOffset(int historicOffset)
Calculates the position in the modified text.

Parameters:
historicOffset - position in the unmodified text.
Returns:
position in the modified text.

retire

public void retire(PositionTracker inFavourOf)
Makes this tracker final. Future changes are tracked by the tracker supplied and will be taken into acoount when converting positions.

Parameters:
inFavourOf - tracker that tracks changes from now on.

print

public void print(java.io.PrintStream out)
For the purpose of testing.


depth

public int depth()
For the purpose of testing.


isModified

public boolean isModified()

getTimeStamp

public long getTimeStamp()

setTimeStamp

public void setTimeStamp(long timeStamp)

getRetiredTimeStamp

public long getRetiredTimeStamp()

getMemorySize

public int getMemorySize()

actualToHistoric

public org.eclipse.jface.text.IRegion actualToHistoric(org.eclipse.jface.text.IRegion actualPosition)
Description copied from interface: IPositionConverter
Converts an actual character range to the range where the underlying text was originally found.

Specified by:
actualToHistoric in interface IPositionConverter
Parameters:
actualPosition - a range as found in the current text buffer for the file.
Returns:
a range suitable for the version of the file for which the converter was obtained.

historicToActual

public org.eclipse.jface.text.IRegion historicToActual(org.eclipse.jface.text.IRegion historicPosition)
Description copied from interface: IPositionConverter
Converts a historic character range to the range where the underlying text currently can be found.

Specified by:
historicToActual in interface IPositionConverter
Parameters:
historicPosition - a range as found in the version of the file for which the converter was obtained.
Returns:
a range suitable for the current text buffer of the file.