|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK 11g Release 2 (11.1.2.2.0) E17493-03 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
oracle.javatools.parser.java.v2.scanner.TokenArray
public final class TokenArray
A precalculated array of tokens. Pay the cost of lexing the first time in order to calculate the array of tokens. All subsequent lexing is a matter of array accesses.
Field Summary | |
---|---|
int |
tokenCount The number of tokens. |
int[] |
tokenEnds The (dense) array of token end offsets. |
int[] |
tokenStarts The (dense) array of token start offsets. |
short[] |
tokenValues The (dense) array of token values. |
Constructor Summary | |
---|---|
TokenArray(FastLexer lexer) |
Method Summary | |
---|---|
void |
adjust(int offset) Adjusts every offset in the token array by the given parameter. |
int |
offset2index(int query, boolean biasAfter) Translates a TextBuffer offset into a TokenArray index with the given bias. |
int |
search(int query) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final int tokenCount
public final short[] tokenValues
public final int[] tokenStarts
public final int[] tokenEnds
Constructor Detail |
---|
public TokenArray(FastLexer lexer)
Method Detail |
---|
public void adjust(int offset)
public int search(int query)
query
- The start offset to be searched for.java.lang.ArrayIndexOutOfBoundsException
- Only if Arrays.binarySearch is wrong or if my array data got corrupted.public int offset2index(int query, boolean biasAfter)
Assumes that all tokens are non-empty (except for the special EOF token). If there are empty tokens (besides the special EOF token), then no guarantee is made regarding the return value.
query
- The offset to be searched for.biasAfter
- True means use an after-bias. Otherwise, use a before-bias. After-bias means choose the next token. Before-bias means choose the previous.Note that whereas EOF is a proper token (the index of EOF is tokenCount-1), start-of-file is not. So, for clarity, if the offset is 0 and the first token is at 0, then 0 is returned, regardless of bias.
If the query is in whitespace, then supposing the query lies between tokens i-1 and i, this will return -(i+1). (This matches the behavior of the Arrays.binarySearch() methods).
To do the math for you, that means that: If the query is before the first token (assuming the first token is not at start-of-file), -1 is returned. If the query is between the last non-EOF token and EOF itself (that is, the file's trailing whitespace), then -tokenCount is returned.
|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK 11g Release 2 (11.1.2.2.0) E17493-03 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |