edu.rice.cs.drjava.model.definitions.reducedmodel
Class ReducedModelComment

java.lang.Object
  extended by edu.rice.cs.drjava.model.definitions.reducedmodel.AbstractReducedModel
      extended by edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedModelComment
All Implemented Interfaces:
ReducedModelStates

public class ReducedModelComment
extends AbstractReducedModel

Keeps track of newlines, comment blocks, and single and double-quoted strings. This reduced sub-model is used for coloring purposes. Given the information contained here, the DefinitionsEditorKit can paint strings, comments, and regular code in different colors. DefinitionsEditorKit colors keywords by directly reading DefinitionsDocument, the "full-scale" model.

Version:
$Id: ReducedModelComment.java 4653 2008-08-26 14:46:35Z rcartwright $

Field Summary
 
Fields inherited from class edu.rice.cs.drjava.model.definitions.reducedmodel.AbstractReducedModel
PTR_CHAR
 
Fields inherited from interface edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedModelStates
FREE, INSIDE_BLOCK_COMMENT, INSIDE_DOUBLE_QUOTE, INSIDE_LINE_COMMENT, INSIDE_SINGLE_QUOTE, STUTTER
 
Constructor Summary
ReducedModelComment()
          Constructor.
 
Method Summary
 void delete(int count)
          Update the BraceReduction to reflect text deletion.
 int getDistToNextNewline()
          Returns the distance to the gap before the next newline (end of document if no newline)
 int getDistToStart()
          Gets distance to the previous newline character (not including newline char).
 int getDistToStart(int relLoc)
          Returns distance to previous newline where relLoc is the distance back from the cursor to start searching.
 ReducedModelState getStateAtCurrent()
          Returns the state of the _cursor iterator.
 void insertChar(char ch)
          Inserts a character into the reduced model.
protected  void insertGapBetweenMultiCharBrace(int length)
          Inserts a gap between the characters in a multiple character brace.
 void insertNewline()
          Inserts an end-of-line character.
 void insertQuote(String quote)
          Inserts the specified quote character.
 boolean isOpenComment()
           
 boolean isShadowed()
           
 boolean isWeaklyShadowed()
           
 void move(int count)
          Updates the BraceReduction to reflect cursor movement.
protected  ReducedModelState moveWalkerGetState(int relLocation)
          Returns the state at the relLocation, where relLocation is the location relative to the walker
protected  void resetWalkerLocationToCursor()
          Resets the walker to the current position in document
 int walkerOffset()
           
 
Methods inherited from class edu.rice.cs.drjava.model.definitions.reducedmodel.AbstractReducedModel
_augmentCurrentGap, _augmentGapToLeft, _gapToLeft, _gapToRight, _insertGap, _insertNewGap, absOffset, absOffset, current, getLength, getState, makeCopyCursor, next, prev, simpleString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReducedModelComment

public ReducedModelComment()
Constructor. Creates a new reduced model with the cursor at the start of a blank "page."

Method Detail

insertChar

public void insertChar(char ch)
Description copied from class: AbstractReducedModel
Inserts a character into the reduced model. A method to be implemented in each specific reduced sub-model.

Specified by:
insertChar in class AbstractReducedModel

insertNewline

public void insertNewline()
Inserts an end-of-line character.
  1. atStart: insert
  2. atEnd: insert
  3. inside multiple character brace:
    1. break current brace
    2. move next to make second part current
    3. insert brace between broken parts of former brace
    4. move previous twice to get before the broken first part
    5. walk
    6. move next twice to be after newline insertion
  4. inside a gap: use helper function
  5. otherwise, just insert normally


insertQuote

public void insertQuote(String quote)
Inserts the specified quote character.
  1. atStart: insert
  2. atEnd: insert
  3. inside multiple character brace:
    1. break current brace
    2. move next to make second part current
    3. insert brace between broken parts of former brace
    4. walk
    5. current = multiple char brace? move next once
      current = single char brace? move next twice
      We moved two previous, but if the broken part combined with the insert, there's only one brace where once were two.
    6. move next twice to be after newline insertion
  4. inside a gap: use helper function
  5. before a multiple char brace:
    1. break the current brace
    2. check previous and insert
  6. otherwise, just insert normally

Parameters:
quote - the type of quote to insert

getStateAtCurrent

public ReducedModelState getStateAtCurrent()
Returns the state of the _cursor iterator.


walkerOffset

public int walkerOffset()

insertGapBetweenMultiCharBrace

protected void insertGapBetweenMultiCharBrace(int length)
Inserts a gap between the characters in a multiple character brace. This function is called by insertGap in AbstractReducedModel when a Gap is inserted between the characters in a comment brace or an escape sequence. It splits up the multiple character brace into its component parts and inserts a Gap of size length in between the resulting split parts.

Specified by:
insertGapBetweenMultiCharBrace in class AbstractReducedModel
Parameters:
length - the size of the Gap to be inserted in characters

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

delete

public void delete(int count)

Update the BraceReduction to reflect 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.

Parameters:
count - indicates the size and direction of text deletion.

isShadowed

public boolean isShadowed()
Returns:
true if the current token is shadowed by a comment or quotation. Note: returns false for the "brace" opening a line, block comment, or quotation.

isWeaklyShadowed

public boolean isWeaklyShadowed()

isOpenComment

public boolean isOpenComment()

moveWalkerGetState

protected ReducedModelState moveWalkerGetState(int relLocation)
Returns the state at the relLocation, where relLocation is the location relative to the walker

Specified by:
moveWalkerGetState in class AbstractReducedModel
Parameters:
relLocation - distance from walker to get state at.

resetWalkerLocationToCursor

protected void resetWalkerLocationToCursor()
Resets the walker to the current position in document

Specified by:
resetWalkerLocationToCursor in class AbstractReducedModel

getDistToStart

public int getDistToStart()
Gets distance to the previous newline character (not including newline char). Returns -1 if no newline exists, so it fails find start of first line.


getDistToStart

public int getDistToStart(int relLoc)
Returns distance to previous newline where relLoc is the distance back from the cursor to start searching.


getDistToNextNewline

public int getDistToNextNewline()
Returns the distance to the gap before the next newline (end of document if no newline)