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

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

 class Brace
extends ReducedToken
implements ReducedModelStates

This class acts as the representation of a brace in the reduced view. It also includes information about the gap of plaintext preceding the actual brace before the previous brace or the start of the file. WARNING: the code in this class critically depends on the fact that literal strings are interned.

Version:
$Id: Brace.java 5175 2010-01-20 08:46:32Z mgricken $

Field Summary
private  int _size
          the type of this brace, which is MUTABLE via flip and setType
private  int _type
           
static int BLK_CMT_BEG_TYPE
           
static int BLK_CMT_END_TYPE
           
static String[] braces
          An array of the special characters that signify areas of text other than gaps.
static int BRACES_LENGTH
           
static int DOUBLE_ESCAPE_TYPE
           
static int DOUBLE_QUOTE_TYPE
           
static int EOLN_TYPE
           
static int ESCAPED_DOUBLE_QUOTE_TYPE
           
static int ESCAPED_SINGLE_QUOTE_TYPE
           
static int LAST_BRACE_INDEX
           
static int LINE_CMT_TYPE
           
static int SINGLE_QUOTE_TYPE
           
static int SLASH_TYPE
           
static int STAR_TYPE
           
 
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
private Brace(int type, ReducedModelState state)
          Constructor.
 
Method Summary
private static int findBrace(String type)
          Determine the brace _type of the given String.
 void flip()
          Flips the orientation of the brace.
 int getSize()
          Get the size of the token.
 String getType()
          Get the text of the brace.
 void grow(int delta)
          Braces can't grow.
 boolean isBlockCommentEnd()
          Determines whether the current location is the end of a block comment
 boolean isBlockCommentStart()
          Determines if current location is the beginning of a block comment
 boolean isClosed()
          Indicates whether this is a closing brace.
 boolean isClosedBrace()
          Determines whether the current location is a closed brace.
 boolean isDoubleEscape()
          Returns whether this is a double escape
 boolean isDoubleEscapeSequence()
          Returns whether this is a double escape sequence
 boolean isDoubleQuote()
          Returns whether this is a double quote
 boolean isEscapedDoubleQuote()
          Return whether this is an escaped double quote
 boolean isEscapedSingleQuote()
          Returns whether this is an escaped single quote
 boolean isGap()
          Implementation of abstract function.
 boolean isLineComment()
          Determines whether the current location is a line comment
 boolean isMatch(Brace other)
          Check if two braces match.
 boolean isMatchable()
          Determines if this Brace is matchable (one of "{", "}", "(", ")", "[", "]").
 boolean isMultipleCharBrace()
          Determines whether the current location is part of a multiple char brace.
 boolean isNewline()
          Determines whether the current location is a new line.
 boolean isOpen()
          Indicates whether this is an opening brace.
 boolean isOpenBrace()
          Determines whether the current location is an open brace.
 boolean isSingleQuote()
          Returns whether this is a single quote
 boolean isSlash()
          Returns whether the current location is a slash
 boolean isStar()
          Returns whether this is a star
static Brace MakeBrace(String type, ReducedModelState state)
          Virtual constructor.
 void setType(String type)
          Reset the type of this brace.
 void shrink(int delta)
          Braces can't shrink.
 String toString()
          Converts a Brace to a String.
 
Methods inherited from class edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedToken
getHighlightState, getState, isCommented, isCommentStart, isQuoted, isShadowed, setState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

braces

public static final String[] braces
An array of the special characters that signify areas of text other than gaps. NOTE: this data structure is NOT simply a flat array. Matching characters are placed next to each other (except for the trailing elements, which have no matches). Notice that single and double quotes match themselves.

See Also:
String

BRACES_LENGTH

public static final int BRACES_LENGTH

LAST_BRACE_INDEX

public static final int LAST_BRACE_INDEX

BLK_CMT_BEG_TYPE

public static final int BLK_CMT_BEG_TYPE

BLK_CMT_END_TYPE

public static final int BLK_CMT_END_TYPE

EOLN_TYPE

public static final int EOLN_TYPE

LINE_CMT_TYPE

public static final int LINE_CMT_TYPE

SINGLE_QUOTE_TYPE

public static final int SINGLE_QUOTE_TYPE

DOUBLE_QUOTE_TYPE

public static final int DOUBLE_QUOTE_TYPE

STAR_TYPE

public static final int STAR_TYPE

SLASH_TYPE

public static final int SLASH_TYPE

DOUBLE_ESCAPE_TYPE

public static final int DOUBLE_ESCAPE_TYPE

ESCAPED_SINGLE_QUOTE_TYPE

public static final int ESCAPED_SINGLE_QUOTE_TYPE

ESCAPED_DOUBLE_QUOTE_TYPE

public static final int ESCAPED_DOUBLE_QUOTE_TYPE

_type

private volatile int _type

_size

private volatile int _size
the type of this brace, which is MUTABLE via flip and setType

Constructor Detail

Brace

private Brace(int type,
              ReducedModelState state)
Constructor.

Parameters:
type - the brace type
state - the state of the reduced model
Method Detail

MakeBrace

public static Brace MakeBrace(String type,
                              ReducedModelState state)
Virtual constructor.

Parameters:
type - the brace text
state - whether the brace is shadwowed by a comment, quote etc
Returns:
a new Brace if type is valid, otherwise null
Throws:
BraceException - if the given type is not a valid brace type.

getType

public String getType()
Get the text of the brace.

Specified by:
getType in class ReducedToken
Returns:
the text of the Brace

getSize

public int getSize()
Description copied from class: ReducedToken
Get the size of the token.

Specified by:
getSize in class ReducedToken
Returns:
the size of the brace and its preceding gap.

toString

public String toString()
Converts a Brace to a String. Used for debugging.

Overrides:
toString in class Object
Returns:
the string representation of the Brace.

flip

public void flip()
Flips the orientation of the brace. Useful for updating quote information. Does not change _size.

Specified by:
flip in class ReducedToken

isOpen

public boolean isOpen()
Indicates whether this is an opening brace.

Specified by:
isOpen in class ReducedToken
Returns:
true if the brace is an opening brace.

isOpenBrace

public boolean isOpenBrace()
Description copied from class: ReducedToken
Determines whether the current location is an open brace.

Specified by:
isOpenBrace in class ReducedToken
Returns:
true if this is {|(|[

isClosedBrace

public boolean isClosedBrace()
Description copied from class: ReducedToken
Determines whether the current location is a closed brace.

Specified by:
isClosedBrace in class ReducedToken
Returns:
true if this is }|)|]

isClosed

public boolean isClosed()
Indicates whether this is a closing brace.

Specified by:
isClosed in class ReducedToken
Returns:
true if the brace is a closing brace.

setType

public void setType(String type)
Reset the type of this brace.

Specified by:
setType in class ReducedToken
Parameters:
type - the new String type for the brace

findBrace

private static int findBrace(String type)
Determine the brace _type of the given String. The integer value returned is only used internally. ASSUMES that the given String is interned! Externally, the brace shows the text as its "type".

Parameters:
type - the text of the brace
Returns:
an integer indicating the type of brace

isMatch

public boolean isMatch(Brace other)
Check if two braces match.

Specified by:
isMatch in class ReducedToken
Parameters:
other - the brace to compare
Returns:
true if this is a match for other.

isMatchable

public boolean isMatchable()
Determines if this Brace is matchable (one of "{", "}", "(", ")", "[", "]").

Specified by:
isMatchable in class ReducedToken

isDoubleQuote

public boolean isDoubleQuote()
Description copied from class: ReducedToken
Returns whether this is a double quote

Specified by:
isDoubleQuote in class ReducedToken
Returns:
true if this is a double quote

isSingleQuote

public boolean isSingleQuote()
Description copied from class: ReducedToken
Returns whether this is a single quote

Specified by:
isSingleQuote in class ReducedToken
Returns:
true if this is a single quote

isLineComment

public boolean isLineComment()
Description copied from class: ReducedToken
Determines whether the current location is a line comment

Specified by:
isLineComment in class ReducedToken
Returns:
true if this is a line comment delimiter

isBlockCommentStart

public boolean isBlockCommentStart()
Description copied from class: ReducedToken
Determines if current location is the beginning of a block comment

Specified by:
isBlockCommentStart in class ReducedToken
Returns:
true if this is a block comment open delimiter

isBlockCommentEnd

public boolean isBlockCommentEnd()
Description copied from class: ReducedToken
Determines whether the current location is the end of a block comment

Specified by:
isBlockCommentEnd in class ReducedToken
Returns:
true if this is a block comment close delimiter

isNewline

public boolean isNewline()
Description copied from class: ReducedToken
Determines whether the current location is a new line.

Specified by:
isNewline in class ReducedToken
Returns:
true if this is a newline delimiter

isMultipleCharBrace

public boolean isMultipleCharBrace()
Description copied from class: ReducedToken
Determines whether the current location is part of a multiple char brace.

Specified by:
isMultipleCharBrace in class ReducedToken
Returns:
true if this is a multiple character brace

isDoubleEscapeSequence

public boolean isDoubleEscapeSequence()
Description copied from class: ReducedToken
Returns whether this is a double escape sequence

Specified by:
isDoubleEscapeSequence in class ReducedToken
Returns:
true if this is \\ or \"

isDoubleEscape

public boolean isDoubleEscape()
Description copied from class: ReducedToken
Returns whether this is a double escape

Specified by:
isDoubleEscape in class ReducedToken
Returns:
true if this is \\

isEscapedDoubleQuote

public boolean isEscapedDoubleQuote()
Description copied from class: ReducedToken
Return whether this is an escaped double quote

Specified by:
isEscapedDoubleQuote in class ReducedToken
Returns:
true if this is \"

isEscapedSingleQuote

public boolean isEscapedSingleQuote()
Description copied from class: ReducedToken
Returns whether this is an escaped single quote

Specified by:
isEscapedSingleQuote in class ReducedToken
Returns:
true if this is \'

isGap

public boolean isGap()
Implementation of abstract function. Braces, of course, are never Gaps.

Specified by:
isGap in class ReducedToken
Returns:
true or false

isSlash

public boolean isSlash()
Description copied from class: ReducedToken
Returns whether the current location is a slash

Specified by:
isSlash in class ReducedToken
Returns:
true if this is /

isStar

public boolean isStar()
Description copied from class: ReducedToken
Returns whether this is a star

Specified by:
isStar in class ReducedToken
Returns:
true if this is *

grow

public void grow(int delta)
Braces can't grow.

Specified by:
grow in class ReducedToken
Throws:
RuntimeException

shrink

public void shrink(int delta)
Braces can't shrink.

Specified by:
shrink in class ReducedToken
Throws:
RuntimeException