KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > token > DefaultToken


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.token;
21
22 import org.netbeans.api.lexer.TokenId;
23
24 /**
25  * Default token which by default obtains text from its background storage.
26  * <br/>
27  * It is non-flyweight and it does not contain custom text.
28  *
29  * <p>
30  * Once the token gets removed from a token list
31  * (because of a text modification) the token
32  * returns <code>null</code> from {@link #text()} because the text
33  * that it would represent could no longer exist in the document.
34  * </p>
35  *
36  * @author Miloslav Metelka
37  * @version 1.00
38  */

39
40 public class DefaultToken<T extends TokenId> extends AbstractToken<T> implements CharSequence JavaDoc {
41     
42     private final int length; // 24 bytes (20-super + 4)
43

44     /**
45      * Construct new default token.
46      */

47     public DefaultToken(T id, int length) {
48         super(id);
49         assert (length > 0) : "Token length=" + length + " <= 0"; // NOI18N
50
this.length = length;
51     }
52     
53     /**
54      * Construct a special zero-length token.
55      */

56     public DefaultToken(T id) {
57         super(id);
58         this.length = 0;
59     }
60
61     @Override JavaDoc
62     public final int length() {
63         return length;
64     }
65
66     @Override JavaDoc
67     protected String JavaDoc dumpInfoTokenType() {
68         return "DefT"; // NOI18N "TextToken" or "FlyToken"
69
}
70     
71 }
72
Popular Tags