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

java.lang.Object
  |
  +--edu.rice.cs.drjava.model.definitions.reducedmodel.AbstractReducedModel
        |
        +--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,v 1.43 2002/03/22 20:35:46 johngarvin Exp $

Field Summary
(package private)  TokenList.Iterator _walker
          Can be used by other classes to walk through the list of comment chars
 
Fields inherited from class edu.rice.cs.drjava.model.definitions.reducedmodel.AbstractReducedModel
_cursor, _tokens, 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
private  void _checkPreviousInsertBackSlash()
          Checks before point of insertion to make sure we don't need to combine backslash with another backslash (yes, they too can be escaped).
private  void _checkPreviousInsertCommentChar(String special)
          Checks before the place of insert to make sure there are no preceding slashes with which the inserted slash must combine.
private  void _checkPreviousInsertSpecial(String special)
          Checks before point of insertion to make sure we don't need to combine.
private  int _getDistToPreviousNewline(TokenList.Iterator copyCursor)
          returns distance to after newline
private  String _getQuoteType(String quote)
          Helper function for insertNewQuote.
private  void _insertNewEndOfLine()
           
private  void _insertNewQuote(String quote)
          Helper function for insertQuote.
private  void _updateBasedOnCurrentState()
          USE RULES: Inserting between braces: This should be called from between the two characters of the broken double comment.
 void delete(int count)
          Update the BraceReduction to reflect text deletion.
(package private)  void getDistToCurrentBraceNewline(IndentInfo braceInfo)
          Computes the distance to the beginning of the line containing the brace enclosing the current location.
(package private)  void getDistToIndentNewline(IndentInfo braceInfo)
           
 int getDistToNextNewline()
          returns the distance to the space before the next newline returns the distance to the end of the document if there is no newline
(package private)  void getDistToPreviousNewline(IndentInfo braceInfo)
          Dist to Previous newline will be -1 if no newline.
 int getDistToPreviousNewline(int relLoc)
          Gets distance to previous newline, relLoc is the distance back from the cursor that we want to start searching.
 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.
private  void insertSpecial(String special)
          Inserts one of three special chars, (*),(/), or (\).
 void move(int count)
          Updates the BraceReduction to reflect cursor movement.
protected  void resetLocation()
          Resets the walker to the current position in document
protected  ReducedModelState stateAtRelLocation(int relLocation)
          Returns the state at the relLocation, where relLocation is the location relative to the walker
 
Methods inherited from class edu.rice.cs.drjava.model.definitions.reducedmodel.AbstractReducedModel
_augmentCurrentGap, _augmentGapToLeft, _gapToLeft, _gapToRight, _insertGap, _insertNewGap, absOffset, current, getBlockOffset, getStateAtCurrent, makeCopyCursor, next, prev, setBlockOffset, simpleString
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

_walker

TokenList.Iterator _walker
Can be used by other classes to walk through the list of comment chars
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.
Overrides:
insertChar in class AbstractReducedModel

insertSpecial

private void insertSpecial(String special)
Inserts one of three special chars, (*),(/), or (\).
  1. empty list: insert slash
  2. atEnd: check previous and insert slash
  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. 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.
  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, check previous and insert

_checkPreviousInsertSpecial

private void _checkPreviousInsertSpecial(String special)
Checks before point of insertion to make sure we don't need to combine. Delegates work to _checkPreviousInsertBackSlash and _checkPreviousInsertCommentChar, depending on what's being inserted into the document.

_checkPreviousInsertBackSlash

private void _checkPreviousInsertBackSlash()
Checks before point of insertion to make sure we don't need to combine backslash with another backslash (yes, they too can be escaped).

_checkPreviousInsertCommentChar

private void _checkPreviousInsertCommentChar(String special)
Checks before the place of insert to make sure there are no preceding slashes with which the inserted slash must combine. It then performs the insert of either (/), (/ /), (/ *) or (* /).

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
Returns:
a Vector of highlighting information after the cursor

_insertNewEndOfLine

private void _insertNewEndOfLine()

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
Returns:
a Vector of highlighting information after the cursor

_insertNewQuote

private void _insertNewQuote(String quote)
Helper function for insertQuote. Creates a new quote Brace and puts it in the reduced model.
Parameters:
quote - the quote to insert

_getQuoteType

private String _getQuoteType(String quote)
Helper function for insertNewQuote. In the case where a backslash precedes the point of insertion, it removes the backslash and returns the text for an escaped quote. The type of quote depends on the given argument.
Parameters:
quote - the type of quote to insert
Returns:
a regular or escaped quote, depending on what was previous

insertGapBetweenMultiCharBrace

protected void insertGapBetweenMultiCharBrace(int length)
Inserts a gap between the characters in a multiple character brace. This function is called by AbstractReducedModel's method insertGap 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.
Overrides:
insertGapBetweenMultiCharBrace in class AbstractReducedModel
Parameters:
length - the size of the Gap to be inserted in characters

_updateBasedOnCurrentState

private void _updateBasedOnCurrentState()
USE RULES: Inserting between braces: This should be called from between the two characters of the broken double comment. Deleting special chars: Start from previous char if it exists. Begins updating at current character. /./ would not become // because current is in the middle. Double character comments inside of a quote or a comment are broken.

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.

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.

stateAtRelLocation

protected ReducedModelState stateAtRelLocation(int relLocation)
Returns the state at the relLocation, where relLocation is the location relative to the walker
Overrides:
stateAtRelLocation in class AbstractReducedModel
Parameters:
relLocation - distance from walker to get state at.

resetLocation

protected void resetLocation()
Resets the walker to the current position in document
Overrides:
resetLocation in class AbstractReducedModel

getDistToPreviousNewline

void getDistToPreviousNewline(IndentInfo braceInfo)
Dist to Previous newline will be -1 if no newline.

_getDistToPreviousNewline

private int _getDistToPreviousNewline(TokenList.Iterator copyCursor)
returns distance to after newline

getDistToIndentNewline

void getDistToIndentNewline(IndentInfo braceInfo)

getDistToCurrentBraceNewline

void getDistToCurrentBraceNewline(IndentInfo braceInfo)
Computes the distance to the beginning of the line containing the brace enclosing the current location. Stores this info in the IndentInfo field distToNewlineCurrent.

getDistToPreviousNewline

public int getDistToPreviousNewline(int relLoc)
Gets distance to previous newline, relLoc is the distance back from the cursor that we want to start searching.

getDistToNextNewline

public int getDistToNextNewline()
returns the distance to the space before the next newline returns the distance to the end of the document if there is no newline