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

java.lang.Object
  |
  +--edu.rice.cs.drjava.model.definitions.reducedmodel.ModelList.Iterator
        |
        +--edu.rice.cs.drjava.model.definitions.reducedmodel.TokenList.Iterator
Enclosing class:
TokenList

public class TokenList.Iterator
extends ModelList.Iterator


Field Summary
private  int _offset
           
 
Fields inherited from class edu.rice.cs.drjava.model.definitions.reducedmodel.ModelList.Iterator
_point, _pos
 
Constructor Summary
  TokenList.Iterator()
           
(package private) TokenList.Iterator(TokenList.Iterator that)
           
 
Method Summary
private  int _calculateOffset(int delToSizePrev, String delToTypePrev, int delToSizeCurr, String delToTypeCurr, TokenList.Iterator delTo)
          By contrasting 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.
private  boolean _checkPrevEquals(TokenList.Iterator delTo, String match)
          Checks if the previous token is of a certain type.
 TokenList.Iterator _copy()
          Makes a fresh copy of this TokenList.Iterator.
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 performs forward moves.
private  int _moveRight(int count, int currentOffset)
          Helper function that performs forward moves.
(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.
 Object current()
          Return the item associated with the current node.
 void delete(int count)
          Update the BraceReduction to reflect text deletion.
(package private)  int deleteRight(TokenList.Iterator delTo)
          Deletes from offset in delFrom to endOffset in delTo.
 int getBlockOffset()
           
 ReducedModelState getStateAtCurrent()
          Returns the current commented/quoted state at the cursor.
 void insert(Object x0)
          Insert an item before the current item.
(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.
 Object nextItem()
          Return the item associated with the node after the current node.
 Object prevItem()
          Return the item associated with the node before the current node.
 void setBlockOffset(int offset)
           
 void setTo(TokenList.Iterator that)
           
 String toString()
           
(package private)  void updateBasedOnCurrentState()
          The walk function.
 
Methods inherited from class edu.rice.cs.drjava.model.definitions.reducedmodel.ModelList.Iterator
atEnd, atFirstItem, atLastItem, atStart, collapse, copy, dispose, eq, next, notifyOfCollapse, notifyOfInsert, notifyOfRemove, prev, remove, setTo
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

_offset

private int _offset
Constructor Detail

TokenList.Iterator

public TokenList.Iterator()

TokenList.Iterator

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 not as fully featured as a TokenList.Iterator. The underscore differentiates between the two. This differentiation was easiest since it allowed us to keep TokenList.Iterator extending ModelList.Iterator.

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. Do not call this unless the current token is a gap!

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.

_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()
The walk function. 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.

move

public void move(int count)
Updates the BraceReduction to reflect cursor movement. Negative values move left from the cursor, positive values move right.
Parameters:
count - indicates the direction and magnitude of cursor movement

_move

private int _move(int count,
                  int currentOffset)
Helper function for move(int).
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 performs forward moves.
  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 performs forward moves.
  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 - indicates the size and direction of text deletion. Negative values delete text to the left of the cursor, positive values delete text to the right. Always move count spaces to make sure we can delete.

_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
offset - current offset for cursor
delFrom - where to delete from
delTo - where to delete to
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 be only partially spanning a token, we need to make sure that this partial span into the non-collapsed token on the right is removed.

deleteRight

int deleteRight(TokenList.Iterator delTo)
Deletes from offset in delFrom to endOffset in delTo. Uses ModelList's collapse function to facilitate quick deletion.

_calculateOffset

private int _calculateOffset(int delToSizePrev,
                             String delToTypePrev,
                             int delToSizeCurr,
                             String delToTypeCurr,
                             TokenList.Iterator delTo)
By contrasting 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 Current is what the current cursor 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

insert

public void insert(Object x0)
Description copied from class: ModelList.Iterator
Insert an item before the current item. If at the containing list's head, we need to move to the next node to perform the insert properly. Otherwise, we'll get a null pointer exception because the function will try to insert the new item before the head. Ends pointing to inserted item.
Overrides:
insert in class ModelList.Iterator

nextItem

public Object nextItem()
Description copied from class: ModelList.Iterator
Return the item associated with the node after the current node.
Overrides:
nextItem in class ModelList.Iterator

prevItem

public Object prevItem()
Description copied from class: ModelList.Iterator
Return the item associated with the node before the current node.
Overrides:
prevItem in class ModelList.Iterator

current

public Object current()
Description copied from class: ModelList.Iterator
Return the item associated with the current node.
Overrides:
current in class ModelList.Iterator