comparison dwtx/jface/text/templates/TemplateTranslator.d @ 136:6dcb0baaa031

Regex removal of throws decls, some instanceof
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 02:20:40 +0200
parents 51e6e63f930e
children 02cd5f1224d3
comparison
equal deleted inserted replaced
135:65801ad2b265 136:6dcb0baaa031
114 this(String name, TemplateVariableType type) { 114 this(String name, TemplateVariableType type) {
115 fName= name; 115 fName= name;
116 fType= type; 116 fType= type;
117 } 117 }
118 118
119 void mergeType(TemplateVariableType type) throws TemplateException { 119 void mergeType(TemplateVariableType type) {
120 if (type is null) 120 if (type is null)
121 return; 121 return;
122 if (fType is null) 122 if (fType is null)
123 fType= type; 123 fType= type;
124 if (!type.equals(fType)) 124 if (!type.equals(fType))
153 * @param template the template to translate. 153 * @param template the template to translate.
154 * @return returns the template buffer corresponding to the string 154 * @return returns the template buffer corresponding to the string
155 * @see #getErrorMessage() 155 * @see #getErrorMessage()
156 * @throws TemplateException if translation failed 156 * @throws TemplateException if translation failed
157 */ 157 */
158 public TemplateBuffer translate(Template template) throws TemplateException { 158 public TemplateBuffer translate(Template template) {
159 return parse(template.getPattern()); 159 return parse(template.getPattern());
160 } 160 }
161 161
162 /** 162 /**
163 * Translates a template string to <code>TemplateBuffer</code>. <code>null</code> is 163 * Translates a template string to <code>TemplateBuffer</code>. <code>null</code> is
167 * @param string the string to translate. 167 * @param string the string to translate.
168 * @return returns the template buffer corresponding to the string 168 * @return returns the template buffer corresponding to the string
169 * @see #getErrorMessage() 169 * @see #getErrorMessage()
170 * @throws TemplateException if translation failed 170 * @throws TemplateException if translation failed
171 */ 171 */
172 public TemplateBuffer translate(String string) throws TemplateException { 172 public TemplateBuffer translate(String string) {
173 return parse(string); 173 return parse(string);
174 } 174 }
175 175
176 /** 176 /**
177 * Internal parser. 177 * Internal parser.
178 * 178 *
179 * @param string the string to parse 179 * @param string the string to parse
180 * @return the parsed <code>TemplateBuffer</code> 180 * @return the parsed <code>TemplateBuffer</code>
181 * @throws TemplateException if the string does not conform to the template format 181 * @throws TemplateException if the string does not conform to the template format
182 */ 182 */
183 private TemplateBuffer parse(String string) throws TemplateException { 183 private TemplateBuffer parse(String string) {
184 184
185 fErrorMessage= null; 185 fErrorMessage= null;
186 final StringBuffer buffer= new StringBuffer(string.length()); 186 final StringBuffer buffer= new StringBuffer(string.length());
187 final Matcher matcher= ESCAPE_PATTERN.matcher(string); 187 final Matcher matcher= ESCAPE_PATTERN.matcher(string);
188 final Map variables= new LinkedHashMap(); 188 final Map variables= new LinkedHashMap();
238 } 238 }
239 239
240 return new TemplateVariableType(typeName, (String[]) params.toArray(new String[params.size()])); 240 return new TemplateVariableType(typeName, (String[]) params.toArray(new String[params.size()]));
241 } 241 }
242 242
243 private void fail(String message) throws TemplateException { 243 private void fail(String message) {
244 fErrorMessage= message; 244 fErrorMessage= message;
245 throw new TemplateException(message); 245 throw new TemplateException(message);
246 } 246 }
247 247
248 /** 248 /**
255 * @param type the variable type, <code>null</code> for not defined 255 * @param type the variable type, <code>null</code> for not defined
256 * @param offset the buffer offset of the variable 256 * @param offset the buffer offset of the variable
257 * @throws TemplateException if merging the type fails 257 * @throws TemplateException if merging the type fails
258 * @since 3.3 258 * @since 3.3
259 */ 259 */
260 private void updateOrCreateVariable(Map variables, String name, TemplateVariableType type, int offset) throws TemplateException { 260 private void updateOrCreateVariable(Map variables, String name, TemplateVariableType type, int offset) {
261 VariableDescription varDesc= cast(VariableDescription) variables.get(name); 261 VariableDescription varDesc= cast(VariableDescription) variables.get(name);
262 if (varDesc is null) { 262 if (varDesc is null) {
263 varDesc= new VariableDescription(name, type); 263 varDesc= new VariableDescription(name, type);
264 variables.put(name, varDesc); 264 variables.put(name, varDesc);
265 } else { 265 } else {