KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > rules > Token


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jface.text.rules;
13
14 import org.eclipse.core.runtime.Assert;
15
16
17 /**
18  * Standard implementation of <code>IToken</code>.
19  */

20 public class Token implements IToken {
21
22     /** Internal token type: Undefined */
23     private static final int T_UNDEFINED= 0;
24     /** Internal token type: EOF */
25     private static final int T_EOF= 1;
26     /** Internal token type: Whitespace */
27     private static final int T_WHITESPACE= 2;
28     /** Internal token type: Others */
29     private static final int T_OTHER= 3;
30
31
32     /**
33      * Standard token: Undefined.
34      */

35     public static final IToken UNDEFINED= new Token(T_UNDEFINED);
36     /**
37      * Standard token: End Of File.
38      */

39     public static final IToken EOF= new Token(T_EOF);
40     /**
41      * Standard token: Whitespace.
42      */

43     public static final IToken WHITESPACE= new Token(T_WHITESPACE);
44
45     /**
46      * Standard token: Neither {@link #UNDEFINED}, {@link #WHITESPACE}, nor {@link #EOF}.
47      * @deprecated will be removed
48      */

49     public static final IToken OTHER= new Token(T_OTHER);
50
51     /** The type of this token */
52     private int fType;
53     /** The data associated with this token */
54     private Object JavaDoc fData;
55
56     /**
57      * Creates a new token according to the given specification which does not
58      * have any data attached to it.
59      *
60      * @param type the type of the token
61      * @since 2.0
62      */

63     private Token(int type) {
64         fType= type;
65         fData= null;
66     }
67
68     /**
69      * Creates a new token which represents neither undefined, whitespace, nor EOF.
70      * The newly created token has the given data attached to it.
71      *
72      * @param data the data attached to the newly created token
73      */

74     public Token(Object JavaDoc data) {
75         fType= T_OTHER;
76         fData= data;
77     }
78
79     /**
80      * Re-initializes the data of this token. The token may not represent
81      * undefined, whitespace, or EOF.
82      *
83      * @param data to be attached to the token
84      * @since 2.0
85      */

86     public void setData(Object JavaDoc data) {
87         Assert.isTrue(isOther());
88         fData= data;
89     }
90
91     /*
92      * @see IToken#getData()
93      */

94     public Object JavaDoc getData() {
95         return fData;
96     }
97
98     /*
99      * @see IToken#isOther()
100      */

101     public boolean isOther() {
102         return (fType == T_OTHER);
103     }
104
105     /*
106      * @see IToken#isEOF()
107      */

108     public boolean isEOF() {
109         return (fType == T_EOF);
110     }
111
112     /*
113      * @see IToken#isWhitespace()
114      */

115     public boolean isWhitespace() {
116         return (fType == T_WHITESPACE);
117     }
118
119     /*
120      * @see IToken#isUndefined()
121      */

122     public boolean isUndefined() {
123         return (fType == T_UNDEFINED);
124     }
125 }
126
Popular Tags