KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > inc > FilterSnapshotTokenList


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.inc;
21
22 import java.util.Set JavaDoc;
23 import org.netbeans.api.lexer.InputAttributes;
24 import org.netbeans.api.lexer.LanguagePath;
25 import org.netbeans.api.lexer.TokenId;
26 import org.netbeans.lib.lexer.EmbeddingContainer;
27 import org.netbeans.lib.lexer.TokenHierarchyOperation;
28 import org.netbeans.lib.lexer.TokenList;
29 import org.netbeans.lib.lexer.token.AbstractToken;
30
31 /**
32  * Filtering token list for token hierarchy snapshots.
33  * <br/>
34  * It holds an offset diff between offset of a token related to particular snapshot
35  * and a "natural" offset of a token (related to null token hierarchy).
36  * <br/>
37  * For non-snapshots it's always zero.
38  * <br/>
39  * It's used for token sequences over embedded token lists because
40  * they are not SnapshotTokenList (only used for root token list) instances
41  * so the embedded token lists need an extra relocation.
42  *
43  * <p>
44  * It also ensures that the modCount will be -1 to eliminate up-to-date checking
45  * for snapshot embedded branches.
46  * </p>
47  *
48  * <p>
49  * This list assumes single-threaded use only.
50  * </p>
51  *
52  * @author Miloslav Metelka
53  * @version 1.00
54  */

55
56 public final class FilterSnapshotTokenList<T extends TokenId> implements TokenList<T> {
57     
58     /** Original token list. */
59     private TokenList<T> tokenList;
60     
61     /**
62      * Difference of the offsets retrieved from tokenList.offset(index)
63      * from the reality - there is a non-zero shift because of the snapshot use.
64      */

65     private int tokenOffsetDiff;
66     
67     public FilterSnapshotTokenList(TokenList<T> tokenList, int tokenOffsetDiff) {
68         this.tokenList = tokenList;
69         this.tokenOffsetDiff = tokenOffsetDiff;
70     }
71     
72     public TokenList delegate() {
73         return tokenList;
74     }
75     
76     public int tokenOffsetDiff() {
77         return tokenOffsetDiff;
78     }
79     
80     public Object JavaDoc tokenOrEmbeddingContainer(int index) {
81         return tokenList.tokenOrEmbeddingContainer(index);
82     }
83
84     public AbstractToken<T> replaceFlyToken(int index, AbstractToken<T> flyToken, int offset) {
85         return tokenList.replaceFlyToken(index, flyToken, offset);
86     }
87
88     public int tokenOffset(int index) {
89         return tokenOffsetDiff + tokenList.tokenOffset(index);
90     }
91
92     public int modCount() {
93         return -1;
94     }
95
96     public int tokenCount() {
97         return tokenList.tokenCount();
98     }
99
100     public int tokenCountCurrent() {
101         return tokenList.tokenCountCurrent();
102     }
103
104     public LanguagePath languagePath() {
105         return tokenList.languagePath();
106     }
107
108     public int childTokenOffset(int rawOffset) {
109         throw new IllegalStateException JavaDoc("Unexpected call.");
110     }
111
112     public char childTokenCharAt(int rawOffset, int index) {
113         throw new IllegalStateException JavaDoc("Unexpected call.");
114     }
115
116     public void wrapToken(int index, EmbeddingContainer<T> embeddingContainer) {
117         tokenList.wrapToken(index, embeddingContainer);
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 InputAttributes inputAttributes() {
129         return tokenList.inputAttributes();
130     }
131
132     public int lookahead(int index) {
133         // Can be used by LexerTestUtilities.lookahead()
134
return tokenList.lookahead(index);
135     }
136
137     public Object JavaDoc state(int index) {
138         return tokenList.state(index);
139     }
140
141     public boolean isContinuous() {
142         return tokenList.isContinuous();
143     }
144
145     public Set JavaDoc<T> skipTokenIds() {
146         return tokenList.skipTokenIds();
147     }
148     
149 }
Popular Tags