edu.rice.cs.drjava.model.definitions.reducedmodel
Class TokenList.Iterator

java.lang.Object
  extended by edu.rice.cs.drjava.model.definitions.reducedmodel.ModelList.ModelIterator
      extended by edu.rice.cs.drjava.model.definitions.reducedmodel.TokenList.Iterator
Enclosing class:
TokenList

public class TokenList.Iterator
extends ModelList.ModelIterator


Field Summary
private  int _offset
           
 
Constructor Summary
  TokenList.Iterator()
           
private TokenList.Iterator(TokenList.Iterator that)
           
 
Method Summary
private  int _calculateOffset(int delToSizePrev, String delToTypePrev, int delToSizeCurr, String delToTypeCurr, TokenList.Iterator delTo)
          By comparing the delTo token after the walk to what it was before the walk we can see how it has changed and where the offset should go.

Prev is the item previous to the current cursor.

private  boolean _checkPrevEquals(TokenList.Iterator delTo, String match)
          Checks if the previous token is of a certain type.
private  int _delete(int count, TokenList.Iterator copyCursor)
          Helper function for delete.
private  int _move(int count, int currentOffset)
          Helper function for move(int).
private  int _moveLeft(int count, int currentOffset)
          Helper function that moves cursor ([iterator pos, count]) backward by count chars.
private  int _moveRight(int count, int currentOffset)
          Helper function that moves cursor ([iterator pos, count]) forward by count chars.
(package private)  void _splitCurrentIfCommentBlock(boolean splitClose, boolean splitEscape)
          Splits the current brace if it is a multiple character brace and fulfills certain conditions.
(package private)  void clipLeft()
          Gets rid of extra text.
(package private)  void clipRight()
          Gets rid of extra text.
 TokenList.Iterator copy()
          Makes a fresh copy of this TokenList.Iterator.
 void delete(int count)
          Update the BraceReduction to reflect text deletion.
(package private)  int deleteRight(TokenList.Iterator delTo)
          Deletes from offset in this to endOffset in delTo.
 int getBlockOffset()
           
 ReducedModelState getStateAtCurrent()
          Returns the current commented/quoted state at the cursor.
(package private)  void insertBraceToGap(String text)
          Handles the details of the case where a brace is inserted into a gap.
(package private)  void insertNewBrace(String text)
          Helper function to _insertBrace.
 void move(int count)
          Updates the BraceReduction to reflect cursor movement.
 void setBlockOffset(int offset)
           
 void setTo(TokenList.Iterator that)
           
 String toString()
           
(package private)  void updateBasedOnCurrentState()
          Walks along the list on which ReducedModel is based from the current cursor position.
 
Methods inherited from class edu.rice.cs.drjava.model.definitions.reducedmodel.ModelList.ModelIterator
atEnd, atFirstItem, atLastItem, atStart, collapse, current, dispose, eq, insert, next, nextItem, pos, prev, prevItem, remove, setTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_offset

private int _offset
Constructor Detail

TokenList.Iterator

public TokenList.Iterator()

TokenList.Iterator

private TokenList.Iterator(TokenList.Iterator that)
Method Detail

copy

public TokenList.Iterator copy()
Makes a fresh copy of this TokenList.Iterator. copy() returns a ModelList.Iterator copy which is more restrictive than TokenList.Iterator. An underscore differentiates the two methods. This differentiation was easiest since it allowed us to keep TokenList.Iterator extending ModelList.Iterator.

Overrides:
copy in class ModelList.ModelIterator

setTo

public void setTo(TokenList.Iterator that)

getBlockOffset

public int getBlockOffset()

setBlockOffset

public void setBlockOffset(int offset)

getStateAtCurrent

public ReducedModelState getStateAtCurrent()
Returns the current commented/quoted state at the cursor.

Returns:
FREE | INSIDE_BLOCK_COMMENT | INSIDE_LINE_COMMENT | INSIDE_SINGLE_QUOTE | INSIDE_DOUBLE_QUOTE

insertBraceToGap

void insertBraceToGap(String text)
Handles the details of the case where a brace is inserted into a gap. Assumes the current token is a gap! Assumes that read lock and reduced locks are already held.


insertNewBrace

void insertNewBrace(String text)
Helper function to _insertBrace. Handles the details of the case where brace is inserted between two reduced tokens. No destructive action is taken. Assume that read lock and reduced lock are already held.


_splitCurrentIfCommentBlock

void _splitCurrentIfCommentBlock(boolean splitClose,
                                 boolean splitEscape)
Splits the current brace if it is a multiple character brace and fulfills certain conditions. If the current brace is a // or /*, split it into two braces. Do the same for star-slash (end comment block) if the parameter splitClose is true. Do the same for \\ and \" if splitEscape is true. If a split was performed, the first of the two Braces will be the current one when we're done. The offset is not changed. The two new Braces will have the same quoted/commented status as the one they were split from.


updateBasedOnCurrentState

void updateBasedOnCurrentState()
Walks along the list on which ReducedModel is based from the current cursor position. Which path it takes depends on the return value of getStateAtCurrent() at the start of the walk. Assumes read lock and reduced lock are already held.


move

public void move(int count)
Updates the BraceReduction to reflect cursor movement. Negative values move left from the cursor, positive values move right. ASSUMES that count is within range, i.e. that the move will not push cursor past start or end.

Parameters:
count - indicates the direction and magnitude of cursor movement

_move

private int _move(int count,
                  int currentOffset)
Helper function for move(int). Assumes that count is in range!

Parameters:
count - the number of chars to move. Negative values move back, positive values move forward.
currentOffset - the current offset for copyCursor
Returns:
the updated offset

_moveRight

private int _moveRight(int count,
                       int currentOffset)
Helper function that moves cursor ([iterator pos, count]) forward by count chars. Assumes that count > 0 and is in range. Returns the new count.
  1. at head && count > 0: next
  2. LOOP:
    if atEnd and count == 0, stop
    if atEnd and count > 0, throw boundary exception
    if count < size of current token, offset = count, stop
    otherwise, reduce count by size of current token and go to the next token, continuing the loop.


_moveLeft

private int _moveLeft(int count,
                      int currentOffset)
Helper function that moves cursor ([iterator pos, count]) backward by count chars. Assumes that count > 0 and is in range. Returns the new count.
  1. atEnd && count > 0: prev
  2. LOOP:
    if atStart and count == 0, stop
    if atStart and count > 0, throw boundary exception
    if count < size of current token, offset = size - count, stop
    otherwise, reduce count by size of current token and go to the previous token, continuing the loop.


delete

public void delete(int count)

Update the BraceReduction to reflect text deletion.

Parameters:
count - A number specifying the size and direction of text deletion. Negative values delete text to the left of the cursor; positive values delete text to the right. Assumes deletion is within range!

_delete

private int _delete(int count,
                    TokenList.Iterator copyCursor)
Helper function for delete. If deleting forward, move delTo the distance forward and call deleteRight.
If deleting backward, move delFrom the distance back and call deleteRight.

Parameters:
count - size of deletion
copyCursor - cursor iterator
Returns:
new offset after deletion

clipLeft

void clipLeft()
Gets rid of extra text. Because collapse cannot get rid of all deletion text as some may be only partially spanning a token, we need to make sure that this partial span into the non-collapsed token on the left is removed.


clipRight

void clipRight()
Gets rid of extra text. Because collapse cannot get rid of all deletion text as some may only partially span a token, we must remove this partial span into the non-collapsed token on the right.


deleteRight

int deleteRight(TokenList.Iterator delTo)
Deletes from offset in this to endOffset in delTo. Uses ModelList.collapse to perform quick deletion.


_calculateOffset

private int _calculateOffset(int delToSizePrev,
                             String delToTypePrev,
                             int delToSizeCurr,
                             String delToTypeCurr,
                             TokenList.Iterator delTo)
By comparing the delTo token after the walk to what it was before the walk we can see how it has changed and where the offset should go.

Prev is the item previous to the current cursor. Curr is the current token. delTo is where current is pointing at this moment in time.


_checkPrevEquals

private boolean _checkPrevEquals(TokenList.Iterator delTo,
                                 String match)
Checks if the previous token is of a certain type.

Parameters:
delTo - the cursor for calling prevItem on
match - the type we want to check
Returns:
true if the previous token is of type match

toString

public String toString()
Overrides:
toString in class Object