Extension SDK 10.1.2

oracle.javatools.editor.language
Class GenericBraceProvider

java.lang.Object
  extended byoracle.javatools.editor.language.GenericBraceProvider
All Implemented Interfaces:
BraceProvider

public class GenericBraceProvider
extends java.lang.Object
implements BraceProvider

The GenericBraceProvider implementation provides brace matching support for "generic" languages that implement the generic Language API to describe the language.

See Also:
BraceProvider, BraceMatchingPlugin

Field Summary
protected  int[] braceArray
          Stores the array containing start and end offsets of brace tokens, as well as brace indexes.
protected  java.lang.String braceCharacters
          String containing all possible brace characters for this language.
protected  int braceCount
          Stores the count of brace tokens in the buffer.
protected  BraceHelper braceHelper
          The brace helper for the language implementation.
protected  GenericLexer lexer
          The lexer to use for the language.
protected  LexerToken lexerToken
          The token to use for lexing.
protected  TextBuffer textBuffer
          The TextBuffer instance used by this GenericBraceProvider.
 
Fields inherited from interface oracle.javatools.editor.language.BraceProvider
BALANCED_MATCH, MISMATCH, UNBALANCED_MATCH
 
Constructor Summary
GenericBraceProvider(LanguageSupport support, Language language)
          Constructs a new GenericBraceProvider associated with the given LanguageSupport and language instance.
GenericBraceProvider(LanguageSupport support, Language language, GenericLexer lexerToUse)
          Constructs a new GenericBraceProvider associated with the given LanguageSupport and language instance.
 
Method Summary
protected  int[] expandBraceArray(int[] braceArray)
          Utility routine to expand the brace array.
protected  void fillBraceArray()
          Utility routine to fill the contents of the brace array.
 int findMatchingBrace(int braceType, NumberRange braceLocation, NumberRange matchingLocation)
          Finds the brace matching the given brace identified by isPartOfBrace().
protected  int guessBraceCount(int length)
          Utility routine to guess the brace count for a given size file.
 int isPartOfBrace(int offset, NumberRange braceLocation)
          Determines whether the character at the given offset is considered a brace or part of a brace in this language.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

textBuffer

protected TextBuffer textBuffer
The TextBuffer instance used by this GenericBraceProvider.


braceHelper

protected BraceHelper braceHelper
The brace helper for the language implementation.


lexer

protected GenericLexer lexer
The lexer to use for the language.


lexerToken

protected LexerToken lexerToken
The token to use for lexing.


braceCharacters

protected java.lang.String braceCharacters
String containing all possible brace characters for this language.


braceArray

protected int[] braceArray
Stores the array containing start and end offsets of brace tokens, as well as brace indexes. This means each entry is stored as a triplet (start, end, index). So the array indexes 0, 3, 6, ... are start offsets (inclusive), the indexes 1, 4, 7, ... are end offsets (exclusive), and the indexes 2, 5, 8 are brace index values.


braceCount

protected int braceCount
Stores the count of brace tokens in the buffer.

Constructor Detail

GenericBraceProvider

public GenericBraceProvider(LanguageSupport support,
                            Language language)
Constructs a new GenericBraceProvider associated with the given LanguageSupport and language instance. This will create a default GenericLexer instance to use.

Parameters:
support - the language support
language - the language definition

GenericBraceProvider

public GenericBraceProvider(LanguageSupport support,
                            Language language,
                            GenericLexer lexerToUse)
Constructs a new GenericBraceProvider associated with the given LanguageSupport and language instance. This allows a given language implementation to use a modified GenericLexer implementation.

Parameters:
support - the language support
language - the language definition
lexerToUse - the lexer to use
Method Detail

isPartOfBrace

public int isPartOfBrace(int offset,
                         NumberRange braceLocation)
Determines whether the character at the given offset is considered a brace or part of a brace in this language. It is conceivable that the brace may consist of multiple characters in certain languages. The NumberRange object passed in by the caller is filled in by this routine to indicate the start and end of the brace at the given offset provided. This routine returns a language-specific token type corresponding to the given brace at the offset, or -1 (Lexer.NOT_FOUND) if the offset is not part of a brace.

Specified by:
isPartOfBrace in interface BraceProvider
Parameters:
offset - the offset in the document associated with the specific LanguageSupport to check if it is a brace
braceLocation - an out parameter to pass start and end offset information to the caller if the provided brace offset is indeed part of a brace
Returns:
a language-specific token type (which should not be interpreted by callers) that should be passed to findMatchingBrace() to find the matching brace.

findMatchingBrace

public int findMatchingBrace(int braceType,
                             NumberRange braceLocation,
                             NumberRange matchingLocation)
Finds the brace matching the given brace identified by isPartOfBrace(). If a matching brace is found, the matchingLocation is filled in with the start and end offsets of the matching brace, and either BALANCED_MATCH or UNBALANCED_MATCH returned depending on whether the braces in between are balanced. If a matching brace is not found, then MISMATCH will be returned, and the contents of matchingLocation are undefined.

Specified by:
findMatchingBrace in interface BraceProvider
Parameters:
braceType - the language-specific token type returned by isPartOfBrace().
braceLocation - the brace location filled in by isPartOfBrace()
matchingLocation - an out parameter to pass start and end offset information to the caller if a matching brace was found
Returns:
BALANCED_MATCH, UNBALANCED_MATCH, or MISMATCH to indicate the result of the match operation

guessBraceCount

protected int guessBraceCount(int length)
Utility routine to guess the brace count for a given size file. This is used to size our brace array buffer.

Parameters:
length - the length of the file
Returns:
the guess of the number of brace tokens in the file

expandBraceArray

protected int[] expandBraceArray(int[] braceArray)
Utility routine to expand the brace array. We assume that all of the brace array contents are valid, as that's the only reason we would need to expand it (it is full.)

Parameters:
braceArray - the old brace array
Returns:
a new brace array of expanded size, with the old contents copied over

fillBraceArray

protected void fillBraceArray()
Utility routine to fill the contents of the brace array.


Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.