KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > batch > SkimTokenList


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.lexer.batch;
21
22 import java.util.Set JavaDoc;
23 import org.netbeans.api.lexer.LanguagePath;
24 import org.netbeans.lib.lexer.EmbeddingContainer;
25 import org.netbeans.lib.lexer.TokenList;
26 import org.netbeans.api.lexer.InputAttributes;
27 import org.netbeans.api.lexer.TokenId;
28 import org.netbeans.lib.lexer.TokenHierarchyOperation;
29 import org.netbeans.lib.lexer.token.AbstractToken;
30
31 /**
32  * Filtering token list constructed over character array with an independent
33  * start offset value.
34  * <br>
35  * It is constructed for batch inputs and it implements
36  * a token list but it only implements translation of raw offsets
37  * into real offsets and retrieving of the characters of token bodies.
38  * <br>
39  * Other operations are delegated to an original
40  * token list that really holds the tokens.
41  *
42  * @author Miloslav Metelka
43  * @version 1.00
44  */

45
46 public final class SkimTokenList<T extends TokenId> implements TokenList<T> {
47     
48     private CopyTextTokenList<T> tokenList;
49     
50     private int startOffset;
51     
52     private char[] text;
53     
54     
55     public SkimTokenList(CopyTextTokenList<T> tokenList, int startOffset, char[] text) {
56         this.tokenList = tokenList;
57         this.startOffset = startOffset;
58         this.text = text;
59     }
60
61     public CopyTextTokenList<T> getTokenList() {
62         return tokenList;
63     }
64     
65     public int getStartOffset() {
66         return startOffset;
67     }
68     
69     char[] getText() {
70         return text;
71     }
72     
73     void setText(char[] text) {
74         this.text = text;
75     }
76
77     public int childTokenOffset(int rawOffset) {
78         int offsetShift = (rawOffset >> 16);
79         return startOffset + (rawOffset & 0xFFFF) + offsetShift;
80     }
81
82     public char childTokenCharAt(int rawOffset, int index) {
83         return text[((rawOffset + index) & 0xFFFF)];
84     }
85
86     public int modCount() {
87         return 0;
88     }
89
90     public Object JavaDoc tokenOrEmbeddingContainer(int index) {
91         return tokenList.tokenOrEmbeddingContainer(index);
92     }
93     
94     public AbstractToken<T> replaceFlyToken(
95     int index, AbstractToken<T> flyToken, int offset) {
96         return tokenList.replaceFlyToken(index, flyToken, offset);
97     }
98     
99
100     public int lookahead(int index) {
101         return tokenList.lookahead(index);
102     }
103
104     public Object JavaDoc state(int index) {
105         return tokenList.state(index);
106     }
107
108     public int tokenOffset(int index) {
109         return tokenList.tokenOffset(index);
110     }
111
112     public int tokenCount() {
113         return tokenList.tokenCount();
114     }
115     
116     public int tokenCountCurrent() {
117         return tokenList.tokenCountCurrent();
118     }
119
120     public TokenList<? extends TokenId> root() {
121         return tokenList.root();
122     }
123
124     public TokenHierarchyOperation<?,? extends TokenId> tokenHierarchyOperation() {
125         return tokenList.tokenHierarchyOperation();
126     }
127     
128     public LanguagePath languagePath() {
129         return tokenList.languagePath();
130     }
131
132     public void wrapToken(int index, EmbeddingContainer embeddingContainer) {
133         tokenList.wrapToken(index, embeddingContainer);
134     }
135
136     public InputAttributes inputAttributes() {
137         return tokenList.inputAttributes();
138     }
139     
140     public boolean isContinuous() {
141         return tokenList.isContinuous();
142     }
143
144     public Set JavaDoc<T> skipTokenIds() {
145         return tokenList.skipTokenIds();
146     }
147
148 }
149
Popular Tags