Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.4.0)

E13403-05

oracle.javatools.editor.language
Class DefaultWordLocator

java.lang.Object
  extended by oracle.javatools.editor.language.DefaultWordLocator
All Implemented Interfaces:
WordLocator

public final class DefaultWordLocator
extends java.lang.Object
implements WordLocator

A simple WordLocator implementation suitable for most artificial languages. The implementation is particularly targetted to Java, but in practice works for a wide variety of languages, including XML. Characters fit into either identifier, punctuation, or space categories. In general, a word is a run of identifier characters followed by a punctuation or space character, or a run of punctuation characters followed by an identifier or space character. Space characters are never part of a word.

Subclasses can redefine what characters are identifier characters by overriding isIdentifierCharacter(int, boolean) and what characters are space characters by overriding isSpaceCharacter(int); punctuation characters are everything else. Subclasses can redefine how word boundaries are recognized by overriding isWordStart(int,boolean,boolean,boolean,boolean) and/or isWordEnd(int,boolean,boolean,boolean,boolean).

See Also:
WordLocator, LanguageSupport.getWordLocator()

Constructor Summary
DefaultWordLocator(LanguageSupport support)
          Constructs a new DefaultWordLocator.
 
Method Summary
 int getNextWordEnd(int offset)
          Gets the offset of the word end after an offset.
 int getNextWordStart(int offset)
          Gets the offset of the word start after an offset.
 int getPreviousWordEnd(int offset)
          Gets the offset of the word end before an offset.
 int getPreviousWordStart(int offset)
          Gets the offset of the word start before an offset.
protected  ReadTextBuffer getTextBuffer()
          Gets the text buffer to which this locator is bound.
 int getWordEnd(int offset)
          Gets the offset of the word end at or after an offset.
 int getWordStart(int offset)
          Gets the offset of the word start at or before an offset.
protected  boolean isIdentifierCharacter(int c, boolean caseChange)
          Gets whether a character is an identifier character.
protected  boolean isSpaceCharacter(int c)
          Gets whether a character is a space character.
protected  boolean isWordEnd(int offset, boolean caseChange, boolean spaceChange, boolean lineStart, boolean lineEnd)
          Gets whether an offset is at the end of a word.
protected  boolean isWordStart(int offset, boolean caseChange, boolean spaceChange, boolean lineStart, boolean lineEnd)
          Gets whether an offset is the start of a word.
protected static boolean useCaseChangeForWordBoundary()
          Gets whether change of case should be considered a word boundary.
protected static boolean useLineEndForWordBoundary()
          Gets whether line end should be considered a word boundary.
protected static boolean useLineStartForWordBoundary()
          Gets whether line start should be considered a word boundary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultWordLocator

public DefaultWordLocator(LanguageSupport support)
Constructs a new DefaultWordLocator.

Parameters:
support - the language support and document this locator is used for
Method Detail

getWordStart

public int getWordStart(int offset)
Gets the offset of the word start at or before an offset.

Specified by:
getWordStart in interface WordLocator
Parameters:
offset - the specified document offset
Returns:
the start of the word that the offset is contained in

getPreviousWordStart

public int getPreviousWordStart(int offset)
Gets the offset of the word start before an offset.

Specified by:
getPreviousWordStart in interface WordLocator
Parameters:
offset - the specified document offset
Returns:
the previous start of a word

getNextWordStart

public int getNextWordStart(int offset)
Gets the offset of the word start after an offset.

Specified by:
getNextWordStart in interface WordLocator
Parameters:
offset - the specified document offset
Returns:
the next start of a word

getWordEnd

public int getWordEnd(int offset)
Gets the offset of the word end at or after an offset. If the specified offset also qualifies as a word start, gets the offset of the word end after the offset.

Specified by:
getWordEnd in interface WordLocator
Parameters:
offset - the specified document offset
Returns:
the end of the word that the offset is contained in

getPreviousWordEnd

public int getPreviousWordEnd(int offset)
Gets the offset of the word end before an offset.

Specified by:
getPreviousWordEnd in interface WordLocator
Parameters:
offset - the specified document offset
Returns:
the previous end of a word

getNextWordEnd

public int getNextWordEnd(int offset)
Gets the offset of the word end after an offset.

Specified by:
getNextWordEnd in interface WordLocator
Parameters:
offset - the specified document offset
Returns:
the next end of a word

getTextBuffer

protected final ReadTextBuffer getTextBuffer()
Gets the text buffer to which this locator is bound.


isSpaceCharacter

protected boolean isSpaceCharacter(int c)
Gets whether a character is a space character. The DefaultWordLocator implementation uses Character.isWhitespace(char).


isIdentifierCharacter

protected boolean isIdentifierCharacter(int c,
                                        boolean caseChange)
Gets whether a character is an identifier character. The DefaultWordLocator implementation uses Character.isJavaIdentifierPart(char) except that an underscore is not considered an identifier if caseChange is true.

Parameters:
caseChange - recognize a word start at change of case.

isWordStart

protected boolean isWordStart(int offset,
                              boolean caseChange,
                              boolean spaceChange,
                              boolean lineStart,
                              boolean lineEnd)
Gets whether an offset is the start of a word. Gets true at BOF and at EOF (although DefaultWordLocator never invokes this method with those offsets).

Parameters:
offset - the offset of the character to test.
caseChange - recognize a word start at change of case.
spaceChange - recognize a word start at start of run of spaces.
lineStart - recognize a word start at line start.
lineEnd - recognize a word start at line end.

isWordEnd

protected boolean isWordEnd(int offset,
                            boolean caseChange,
                            boolean spaceChange,
                            boolean lineStart,
                            boolean lineEnd)
Gets whether an offset is at the end of a word. Gets true at BOF or EOF (although DefaultWordLocator never invokes this method with those offsets).

Parameters:
offset - the offset of the character to test.
caseChange - recognize a word end at change of case.
spaceChange - recognize a word end at end of run of spaces.
lineStart - recognize a word end at line start.
lineEnd - recognize a word end at line end.

useCaseChangeForWordBoundary

protected static boolean useCaseChangeForWordBoundary()
Gets whether change of case should be considered a word boundary.


useLineStartForWordBoundary

protected static boolean useLineStartForWordBoundary()
Gets whether line start should be considered a word boundary.


useLineEndForWordBoundary

protected static boolean useLineEndForWordBoundary()
Gets whether line end should be considered a word boundary.


Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.4.0)

E13403-05

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