KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
33  * Single token list maintains a text for a single token.
34  *
35  * @author Miloslav Metelka
36  * @version 1.00
37  */

38
39 public final class StandaloneTokenList<T extends TokenId> implements TokenList<T> {
40
41     private char[] tokenText;
42
43     private LanguagePath languagePath;
44     
45     public StandaloneTokenList(LanguagePath languagePath, char[] tokenText) {
46         this.languagePath = languagePath;
47         this.tokenText = tokenText;
48     }
49     
50     public LanguagePath languagePath() {
51         return languagePath;
52     }
53     
54     public Object JavaDoc tokenOrEmbeddingContainer(int index) {
55         throw new IllegalStateException JavaDoc("Not expected to be called"); // NOI18N
56
}
57
58     public AbstractToken<T> replaceFlyToken(
59     int index, AbstractToken<T> flyToken, int offset) {
60         throw new IllegalStateException JavaDoc("Not expected to be called"); // NOI18N
61
}
62
63     public int lookahead(int index) {
64         return -1;
65     }
66
67     public Object JavaDoc state(int index) {
68         return null;
69     }
70
71     public int tokenOffset(int index) {
72         throw new IllegalStateException JavaDoc("Not expected to be called"); // NOI18N
73
}
74     
75     public int tokenCount() {
76         return 1;
77     }
78
79     public int tokenCountCurrent() {
80         return 1;
81     }
82
83     public int modCount() {
84         return -1;
85     }
86     
87     public int childTokenOffset(int rawOffset) {
88         // Offset of the standalone token is absolute
89
return rawOffset;
90     }
91     
92     public char childTokenCharAt(int rawOffset, int index) {
93         return tokenText[index];
94     }
95
96     public void wrapToken(int index, EmbeddingContainer embeddingContainer) {
97         throw new IllegalStateException JavaDoc("Branching of standalone tokens not supported"); // NOI18N
98
}
99     
100     public TokenList<? extends TokenId> root() {
101         return this;
102     }
103     
104     public TokenHierarchyOperation<?,? extends TokenId> tokenHierarchyOperation() {
105         return null;
106     }
107     
108     public InputAttributes inputAttributes() {
109         throw new IllegalStateException JavaDoc("Not expected to be called"); // NOI18N
110
}
111     
112     public boolean isContinuous() {
113         return true;
114     }
115
116     public Set JavaDoc<T> skipTokenIds() {
117         return null;
118     }
119
120 }
121
Popular Tags