Mercurial > projects > dwt-addons
annotate dwtx/jface/text/rules/Token.d @ 199:eb98a5cbfd78
Fix: potential problem with synchronized, thx torhu.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 13 Mar 2009 17:03:26 +0100 |
parents | 1a5b8f8129df |
children |
rev | line source |
---|---|
129 | 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 | |
131 | 14 |
151 | 15 module dwtx.jface.text.rules.Token; |
16 | |
131 | 17 import dwtx.jface.text.rules.FastPartitioner; // packageimport |
18 import dwtx.jface.text.rules.ITokenScanner; // packageimport | |
19 import dwtx.jface.text.rules.RuleBasedScanner; // packageimport | |
20 import dwtx.jface.text.rules.EndOfLineRule; // packageimport | |
21 import dwtx.jface.text.rules.WordRule; // packageimport | |
22 import dwtx.jface.text.rules.WhitespaceRule; // packageimport | |
23 import dwtx.jface.text.rules.WordPatternRule; // packageimport | |
24 import dwtx.jface.text.rules.IPredicateRule; // packageimport | |
25 import dwtx.jface.text.rules.DefaultPartitioner; // packageimport | |
26 import dwtx.jface.text.rules.NumberRule; // packageimport | |
27 import dwtx.jface.text.rules.SingleLineRule; // packageimport | |
28 import dwtx.jface.text.rules.PatternRule; // packageimport | |
29 import dwtx.jface.text.rules.RuleBasedDamagerRepairer; // packageimport | |
30 import dwtx.jface.text.rules.ICharacterScanner; // packageimport | |
31 import dwtx.jface.text.rules.IRule; // packageimport | |
32 import dwtx.jface.text.rules.DefaultDamagerRepairer; // packageimport | |
33 import dwtx.jface.text.rules.IToken; // packageimport | |
34 import dwtx.jface.text.rules.IPartitionTokenScanner; // packageimport | |
35 import dwtx.jface.text.rules.MultiLineRule; // packageimport | |
36 import dwtx.jface.text.rules.RuleBasedPartitioner; // packageimport | |
37 import dwtx.jface.text.rules.RuleBasedPartitionScanner; // packageimport | |
38 import dwtx.jface.text.rules.BufferedRuleBasedScanner; // packageimport | |
39 import dwtx.jface.text.rules.IWhitespaceDetector; // packageimport | |
40 | |
129 | 41 import dwt.dwthelper.utils; |
42 | |
43 import dwtx.core.runtime.Assert; | |
44 | |
45 | |
46 /** | |
47 * Standard implementation of <code>IToken</code>. | |
48 */ | |
49 public class Token : IToken { | |
50 | |
51 /** Internal token type: Undefined */ | |
147 | 52 private static const int T_UNDEFINED= 0; |
129 | 53 /** Internal token type: EOF */ |
147 | 54 private static const int T_EOF= 1; |
129 | 55 /** Internal token type: Whitespace */ |
147 | 56 private static const int T_WHITESPACE= 2; |
129 | 57 /** Internal token type: Others */ |
147 | 58 private static const int T_OTHER= 3; |
129 | 59 |
60 | |
61 /** | |
62 * Standard token: Undefined. | |
63 */ | |
162 | 64 public static IToken UNDEFINED_; |
65 public static IToken UNDEFINED(){ | |
66 if( UNDEFINED_ is null ){ | |
67 synchronized( Token.classinfo ){ | |
68 if( UNDEFINED_ is null ){ | |
69 UNDEFINED_ = new Token(T_UNDEFINED); | |
70 } | |
71 } | |
72 } | |
73 return UNDEFINED_; | |
74 } | |
129 | 75 /** |
76 * Standard token: End Of File. | |
77 */ | |
162 | 78 public static IToken EOF_; |
79 public static IToken EOF(){ | |
80 if( EOF_ is null ){ | |
81 synchronized( Token.classinfo ){ | |
82 if( EOF_ is null ){ | |
83 EOF_ = new Token(T_EOF); | |
84 } | |
85 } | |
86 } | |
87 return EOF_; | |
88 } | |
129 | 89 /** |
90 * Standard token: Whitespace. | |
91 */ | |
162 | 92 public static IToken WHITESPACE_; |
93 public static IToken WHITESPACE(){ | |
94 if( WHITESPACE_ is null ){ | |
95 synchronized( Token.classinfo ){ | |
96 if( WHITESPACE_ is null ){ | |
97 WHITESPACE_ = new Token(T_WHITESPACE); | |
98 } | |
99 } | |
100 } | |
101 return WHITESPACE_; | |
102 } | |
129 | 103 |
104 /** | |
105 * Standard token: Neither {@link #UNDEFINED}, {@link #WHITESPACE}, nor {@link #EOF}. | |
106 * @deprecated will be removed | |
107 */ | |
162 | 108 public static IToken OTHER_; |
109 public static IToken OTHER(){ | |
110 if( OTHER_ is null ){ | |
111 synchronized( Token.classinfo ){ | |
112 if( OTHER_ is null ){ | |
113 OTHER_ = new Token(T_OTHER); | |
114 } | |
115 } | |
116 } | |
117 return OTHER_; | |
118 } | |
129 | 119 |
120 /** The type of this token */ | |
121 private int fType; | |
122 /** The data associated with this token */ | |
123 private Object fData; | |
124 | |
125 /** | |
126 * Creates a new token according to the given specification which does not | |
127 * have any data attached to it. | |
128 * | |
129 * @param type the type of the token | |
130 * @since 2.0 | |
131 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
132 private this(int type) { |
129 | 133 fType= type; |
134 fData= null; | |
135 } | |
136 | |
137 /** | |
138 * Creates a new token which represents neither undefined, whitespace, nor EOF. | |
139 * The newly created token has the given data attached to it. | |
140 * | |
141 * @param data the data attached to the newly created token | |
142 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
143 public this(Object data) { |
129 | 144 fType= T_OTHER; |
145 fData= data; | |
146 } | |
147 | |
148 /** | |
149 * Re-initializes the data of this token. The token may not represent | |
150 * undefined, whitespace, or EOF. | |
151 * | |
152 * @param data to be attached to the token | |
153 * @since 2.0 | |
154 */ | |
155 public void setData(Object data) { | |
156 Assert.isTrue(isOther()); | |
157 fData= data; | |
158 } | |
159 | |
160 /* | |
161 * @see IToken#getData() | |
162 */ | |
163 public Object getData() { | |
164 return fData; | |
165 } | |
166 | |
167 /* | |
168 * @see IToken#isOther() | |
169 */ | |
170 public bool isOther() { | |
171 return (fType is T_OTHER); | |
172 } | |
173 | |
174 /* | |
175 * @see IToken#isEOF() | |
176 */ | |
177 public bool isEOF() { | |
178 return (fType is T_EOF); | |
179 } | |
180 | |
181 /* | |
182 * @see IToken#isWhitespace() | |
183 */ | |
184 public bool isWhitespace() { | |
185 return (fType is T_WHITESPACE); | |
186 } | |
187 | |
188 /* | |
189 * @see IToken#isUndefined() | |
190 */ | |
191 public bool isUndefined() { | |
192 return (fType is T_UNDEFINED); | |
193 } | |
194 } |