Java Doc for TokenSequence.java in  » IDE-Netbeans » lexer » org » netbeans » api » lexer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » lexer » org.netbeans.api.lexer 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.netbeans.api.lexer.TokenSequence

TokenSequence
final public class TokenSequence (Code)
Token sequence allows to iterate between tokens of a token hierarchy.
Token sequence for top-level language of a token hierarchy may be obtained by TokenHierarchy.tokenSequence .

Use of token sequence is a two-step operation:

  1. Position token sequence before token that should first be retrieved (or behind desired token when iterating backwards).
    One of the following ways may be used: Token sequence will always be positioned between tokens when using one of the operations above ( TokenSequence.token() will return null to signal between-tokens location).
  2. Start iterating through the tokens in forward/backward direction by using TokenSequence.moveNext() or TokenSequence.movePrevious() .
    If moveNext() or movePrevious() returned true then TS is positioned over a concrete token retrievable by TokenSequence.token() .
    Its offset can be retrieved by TokenSequence.offset() .

An example of forward iteration through the tokens:

 TokenSequence ts = tokenHierarchy.tokenSequence();
 // Possible positioning by ts.move(offset) or ts.moveIndex(index)
 while (ts.moveNext()) {
 Token t = ts.token();
 if (t.id() == ...) { ... }
 if (TokenUtilities.equals(t.text(), "mytext")) { ... }
 if (ts.offset() == ...) { ... }
 }
 

This object should be used by a single thread only. For token hierarchies over mutable input sources the obtaining and using of the token sequence needs to be done under a read-lock of the input source.


author:
   Miloslav Metelka
version:
   1.00



Constructor Summary
 TokenSequence(TokenList<T> tokenList)
     Package-private constructor used by API accessor.

Method Summary
public  booleancreateEmbedding(Language embeddedLanguage, int startSkipLength, int endSkipLength)
     Create language embedding without joining of the embedded sections.
public  booleancreateEmbedding(Language embeddedLanguage, int startSkipLength, int endSkipLength, boolean joinSections)
     Create language embedding described by the given parameters.
If the underying text input is mutable then this method should only be called within a write lock over the text input.
Parameters:
  embeddedLanguage - non-null embedded language
Parameters:
  startSkipLength - >=0 number of characters in an initial part of the tokenfor which the language embedding is defined that should be excludedfrom the embedded section.
public  TokenSequenceembedded()
     Get embedded token sequence if the token to which this token sequence is currently positioned has a language embedding.
public  TokenSequence<ET>embedded(Language<ET> embeddedLanguage)
     Get embedded token sequence if the token to which this token sequence is currently positioned has a language embedding.
public  intindex()
     Get an index of token to which (or before which) this TS is currently positioned.

Initially or after TokenSequence.move(int) or TokenSequence.moveIndex(int) token sequence is positioned between tokens:

 Token[0]   Token[1]   ...
public  booleanisEmpty()
     Check whether this TS contains zero tokens.
public  booleanisValid()
     Check whether this token sequence is valid and can be iterated.
public  Language<T>language()
     Get the language describing token ids used by tokens in this token sequence.
public  LanguagePathlanguagePath()
     Get the complete language path of the tokens contained in this token sequence.
public  intmove(int offset)
     Move token sequence to be positioned between index-1 and index tokens where Token[index] either starts at offset or "contains" the offset.
 +----------+-----+----------------+--------------+------
 | Token[0] | ...
public  voidmoveEnd()
     Move the token sequence to be positioned behind the last token.
public  intmoveIndex(int index)
     Position token sequence between index-1 and index tokens.
TS will be positioned in the following way:
 Token[0]   ...
public  booleanmoveNext()
     Move to the next token in this token sequence.

The next token may not necessarily start at the offset where the previous token ends (there may be gaps between tokens caused by token filtering).

public  booleanmovePrevious()
     Move to a previous token in this token sequence.

The previous token may not necessarily end at the offset where the previous token started (there may be gaps between tokens caused by token filtering).

public  voidmoveStart()
     Move the token sequence to be positioned before the first token.
public  intoffset()
     Get the offset of the current token in the underlying input.
public  Token<T>offsetToken()
     Similar to TokenSequence.token() but always returns a non-flyweight token with the appropriate offset.
If the current token is flyweight then this method replaces it with the corresponding non-flyweight token which it then returns.
Subsequent calls to TokenSequence.token() will also return this non-flyweight token.

This method may be handy if the token instance is referenced in a standalone way (e.g.

public  booleanremoveEmbedding(Language embeddedLanguage)
     Remove previously created language embedding.
public  TokenSequence<T>subSequence(int startOffset)
     Create sub sequence of this token sequence that only returns tokens above the given offset.
Parameters:
  startOffset - only tokens satisfyingtokenStartOffset + tokenLength > startOffsetwill be present in the returned sequence.
public  TokenSequence<T>subSequence(int startOffset, int endOffset)
     Create sub sequence of this token sequence that only returns tokens between the given offsets.
Parameters:
  startOffset - only tokens satisfyingtokenStartOffset + tokenLength > startOffsetwill be present in the returned sequence.
Parameters:
  endOffset - >=startOffset only tokens satisfyingtokenStartOffset < endOffsetwill be present in the returned sequence.
public  StringtoString()
    
public  Token<T>token()
     Get token to which this token sequence points to or null if TS is positioned between tokens ( TokenSequence.moveNext() or TokenSequence.movePrevious() were not called yet).
A typical iteration usage:
 TokenSequence ts = tokenHierarchy.tokenSequence();
 // Possible positioning by ts.move(offset) or ts.moveIndex(index)
 while (ts.moveNext()) {
 Token t = ts.token();
 if (t.id() == ...) { ...
public  inttokenCount()
     Return total count of tokens in this sequence.


Constructor Detail
TokenSequence
TokenSequence(TokenList<T> tokenList)(Code)
Package-private constructor used by API accessor.




Method Detail
createEmbedding
public boolean createEmbedding(Language embeddedLanguage, int startSkipLength, int endSkipLength)(Code)
Create language embedding without joining of the embedded sections.
throws:
  IllegalStateException - if TokenSequence.token() returns null.
See Also:   TokenSequence.createEmbedding(Language,int,int,boolean)



createEmbedding
public boolean createEmbedding(Language embeddedLanguage, int startSkipLength, int endSkipLength, boolean joinSections)(Code)
Create language embedding described by the given parameters.
If the underying text input is mutable then this method should only be called within a write lock over the text input.
Parameters:
  embeddedLanguage - non-null embedded language
Parameters:
  startSkipLength - >=0 number of characters in an initial part of the tokenfor which the language embedding is defined that should be excludedfrom the embedded section. The excluded characters will not be lexedand there will be no tokens created for them.
Parameters:
  endSkipLength - >=0 number of characters at the end of the tokenfor which the language embedding is defined that should be excludedfrom the embedded section. The excluded characters will not be lexedand there will be no tokens created for them.
Parameters:
  joinSections - whether sections with this embedding should be joinedacross the input source or whether they should stay separate.
For example for HTML sections embedded in JSP this flag should be true:
<!-- HTML comment start<% System.out.println("Hello"); %>still in HTML comment --<

Only the embedded sections with the same language path can be joined. true if the embedding was created successfully or false if an embeddingwith the given language already exists for this token.
throws:
  IllegalStateException - if TokenSequence.token() returns null.



embedded
public TokenSequence embedded()(Code)
Get embedded token sequence if the token to which this token sequence is currently positioned has a language embedding.
If there is a custom embedding created by TokenSequence.createEmbedding(Language,int,int) it will be returned instead of the default embedding (the one created by LanguageHierarchy.embedding() or LanguageProvider). embedded sequence or null if no embedding exists for this token.
throws:
  IllegalStateException - if TokenSequence.token() returns null.



embedded
public TokenSequence<ET> embedded(Language<ET> embeddedLanguage)(Code)
Get embedded token sequence if the token to which this token sequence is currently positioned has a language embedding.
throws:
  IllegalStateException - if TokenSequence.token() returns null.



index
public int index()(Code)
Get an index of token to which (or before which) this TS is currently positioned.

Initially or after TokenSequence.move(int) or TokenSequence.moveIndex(int) token sequence is positioned between tokens:

 Token[0]   Token[1]   ...   Token[n]
 ^          ^                ^
 Index: 0          1                n
 

After use of TokenSequence.moveNext() or TokenSequence.movePrevious() the token sequence is positioned over one of the actual tokens:

 Token[0]   Token[1]   ...   Token[n]
 ^          ^                ^
 Index:      0          1                n
 

>=0 index of token to which (or before which) this TS is currently positioned.



isEmpty
public boolean isEmpty()(Code)
Check whether this TS contains zero tokens.
This check is strongly preferred over tokenCount() == 0.
See Also:   TokenSequence.tokenCount()



isValid
public boolean isValid()(Code)
Check whether this token sequence is valid and can be iterated.
If this method returns false then the underlying token hierarchy was modified and this token sequence should be abandoned. true if this token sequence is ready for use or false if it should be abandoned.



language
public Language<T> language()(Code)
Get the language describing token ids used by tokens in this token sequence.



languagePath
public LanguagePath languagePath()(Code)
Get the complete language path of the tokens contained in this token sequence.



move
public int move(int offset)(Code)
Move token sequence to be positioned between index-1 and index tokens where Token[index] either starts at offset or "contains" the offset.
 +----------+-----+----------------+--------------+------
 | Token[0] | ... | Token[index-1] | Token[index] | ...
 | "public" | ... | "static"       | "int"        | ...
 +----------+-----+----------------+--------------+------
 ^                ^                ^
 Index: 0             index-1           index
 Offset:                                  ---^ (if offset points to 'i','n' or 't')
 

Subsequent TokenSequence.moveNext() or TokenSequence.movePrevious() is needed to fetch a concrete token.
If the offset is too big then the token sequence will be positioned behind the last token.

If token filtering is used there may be gaps that are not covered by any tokens and if the offset is contained in such gap then the token sequence will be positioned before the token that follows the gap.


Parameters:
  offset - absolute offset to which the token sequence should be moved. difference between the reqeuested offsetand the start offset of the tokenbefore which the the token sequence gets positioned.
throws:
  ConcurrentModificationException - if this token sequenceis no longer valid because of an underlying mutable input source modification.



moveEnd
public void moveEnd()(Code)
Move the token sequence to be positioned behind the last token.
This is equivalent to moveIndex(tokenCount()).



moveIndex
public int moveIndex(int index)(Code)
Position token sequence between index-1 and index tokens.
TS will be positioned in the following way:
 Token[0]   ...   Token[index-1]   Token[index] ...
 ^                ^                ^
 Index: 0             index-1           index
 

Subsequent TokenSequence.moveNext() or TokenSequence.movePrevious() is needed to fetch a concrete token in the desired direction.
Subsequent TokenSequence.moveNext() will position TS over Token[index] (or TokenSequence.movePrevious() will position TS over Token[index-1]) so that TokenSequence.token() != null.
Parameters:
  index - index of the token to which this sequenceshould be positioned.
If index >= TokenSequence.tokenCount()then the TS will be positioned to TokenSequence.tokenCount().
If index < 0 then the TS will be positioned to index 0. difference between requested index and the index to which TSis really set.
throws:
  ConcurrentModificationException - if this token sequenceis no longer valid because of an underlying mutable input source modification.




moveNext
public boolean moveNext()(Code)
Move to the next token in this token sequence.

The next token may not necessarily start at the offset where the previous token ends (there may be gaps between tokens caused by token filtering). TokenSequence.offset() should be used for offset retrieval.

true if the sequence was successfully moved to the next tokenor false if it was not moved before there are no more tokensin the forward direction.
throws:
  ConcurrentModificationException - if this token sequenceis no longer valid because of an underlying mutable input source modification.



movePrevious
public boolean movePrevious()(Code)
Move to a previous token in this token sequence.

The previous token may not necessarily end at the offset where the previous token started (there may be gaps between tokens caused by token filtering). TokenSequence.offset() should be used for offset retrieval.

true if the sequence was successfully moved to the previous tokenor false if it was not moved because there are no more tokensin the backward direction.
throws:
  ConcurrentModificationException - if this token sequenceis no longer valid because of an underlying mutable input source modification.



moveStart
public void moveStart()(Code)
Move the token sequence to be positioned before the first token.
This is equivalent to moveIndex(0).



offset
public int offset()(Code)
Get the offset of the current token in the underlying input.
The token's offset should never be computed by a client of the token sequence by adding/subtracting tokens' length to a client's variable because in case of the immutable token sequences there can be gaps between tokens if some tokens get filtered out.
Instead this method should always be used because it offers best performance with a constant time complexity. >=0 absolute offset of the current token in the underlying input.
throws:
  IllegalStateException - if TokenSequence.token() returns null.



offsetToken
public Token<T> offsetToken()(Code)
Similar to TokenSequence.token() but always returns a non-flyweight token with the appropriate offset.
If the current token is flyweight then this method replaces it with the corresponding non-flyweight token which it then returns.
Subsequent calls to TokenSequence.token() will also return this non-flyweight token.

This method may be handy if the token instance is referenced in a standalone way (e.g. in an expression node of a parse tree) and it's necessary to get the appropriate offset from the token itself later when a token sequence will not be available.


throws:
  IllegalStateException - if TokenSequence.token() returns null.



removeEmbedding
public boolean removeEmbedding(Language embeddedLanguage)(Code)
Remove previously created language embedding.
If the underying text input is mutable then this method should only be called within a write lock over the text input.



subSequence
public TokenSequence<T> subSequence(int startOffset)(Code)
Create sub sequence of this token sequence that only returns tokens above the given offset.
Parameters:
  startOffset - only tokens satisfyingtokenStartOffset + tokenLength > startOffsetwill be present in the returned sequence. non-null sub sequence of this token sequence.



subSequence
public TokenSequence<T> subSequence(int startOffset, int endOffset)(Code)
Create sub sequence of this token sequence that only returns tokens between the given offsets.
Parameters:
  startOffset - only tokens satisfyingtokenStartOffset + tokenLength > startOffsetwill be present in the returned sequence.
Parameters:
  endOffset - >=startOffset only tokens satisfyingtokenStartOffset < endOffsetwill be present in the returned sequence. non-null sub sequence of this token sequence.



toString
public String toString()(Code)



token
public Token<T> token()(Code)
Get token to which this token sequence points to or null if TS is positioned between tokens ( TokenSequence.moveNext() or TokenSequence.movePrevious() were not called yet).
A typical iteration usage:
 TokenSequence ts = tokenHierarchy.tokenSequence();
 // Possible positioning by ts.move(offset) or ts.moveIndex(index)
 while (ts.moveNext()) {
 Token t = ts.token();
 if (t.id() == ...) { ... }
 if (TokenUtilities.equals(t.text(), "mytext")) { ... }
 if (ts.offset() == ...) { ... }
 }
 
The returned token instance may be flyweight ( Token.isFlyweight returns true) which means that its Token.offset(TokenHierarchy) will return -1.
To find a correct offset use TokenSequence.offset() .
Or if its necessary to revert to a regular non-flyweigt token the TokenSequence.offsetToken() may be used.

The lifetime of the returned token instance may be limited for mutable inputs. The token instance should not be held across the input source modifications.

token instance to which this token sequence is currently positionedor null if this token sequence is not positioned to any token which mayhappen after TS creation or after use of TokenSequence.move(int) or TokenSequence.moveIndex(int).
See Also:   TokenSequence.offsetToken()



tokenCount
public int tokenCount()(Code)
Return total count of tokens in this sequence.
Note: Calling this method will lead to creation of all the remaining tokens in the sequence if they were not yet created. total number of tokens in this token sequence.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.