1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
/* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This file is part of the debugger and core tools for the AspectJ(tm)
* programming language; see http://aspectj.org
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is AspectJ.
*
* The Initial Developer of the Original Code is Xerox Corporation. Portions
* created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
* All Rights Reserved.
*/
package org.aspectj.tools.ajdoc;
import org.aspectj.compiler.base.ErrorHandler;
import org.aspectj.compiler.base.InternalCompilerError;
import com.sun.javadoc.DocErrorReporter;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* A class to handler errors in ajdoc.
*
* @author Jeff Palm
*/
public class ErrPrinter
extends ErrorHandler
implements DocErrorReporter
{
/** The global instance that anyone can use. */
public final static ErrPrinter instance = new ErrPrinter();
private String programName;
private PrintWriter out;
private PrintWriter err;
private ResourceBundle bundle;
private List keys = new ArrayList();
private List msgs = new ArrayList();
static int cnt = 0;
/**
* Construct with program name <code>programName</code>
* and printstreams <code>err</code> and <code>out</code>.
*
* @param programName program name.
* @param err error stream.
* @param out output stream.
*/
public ErrPrinter(String programName,
PrintWriter err,
PrintWriter out) {
super(err);
this.programName = programName;
this.err = err;
this.out = out;
try {
bundle = ResourceBundle.getBundle
("org.aspectj.tools.ajdoc.resources.ajdoc");
} catch (MissingResourceException e) {
throw new Error("Can't find ajdoc.properties: " + e);
}
}
/**
* Construct with program name <code>programName</code>
* and printstreams <code>System.err</code> and <code>System.out</code>
*
* @param programName program name.
*/
public ErrPrinter(String programName) {
this(programName,
new PrintWriter(System.err, true),
new PrintWriter(System.out, true));
}
/**
* Construct with program name <code>"ajdoc"</code>
* and printstreams <code>System.err</code> and <code>System.out</code>
*/
public ErrPrinter() {
this("ajdoc");
}
/**
* Print <code>error</code> and increment the error count.
*
* @param error error message to print.
*/
public void printError(String error) {
errors++;
err.println(error);
err.flush();
}
/**
* Print <code>warning</code> and increment the warning count.
*
* @param warning warning message to print.
*/
public void printWarning(String warning) {
warnings++;
err.println(warning);
err.flush();
}
/**
* Print <code>notice</code>.
*
* @param notice notice message to print.
*/
public void printNotice(String notice) {
out.println(notice);
out.flush();
}
/**
* Returns the number of errors.
*
* @return number of errors.
*/
public int getNumErrors() {
return errors;
}
/**
* Returns the number of warnings.
*
* @return number of warnings.
*/
public int getNumWarnings() {
return warnings;
}
/**
* Returns the keys in the resource bundle.
*
* @return keys in the resource bundle.
*/
public List getKeys() {
return new ArrayList(keys);
}
/**
* Returns the messages in the resource bundle.
*
* @return messages in the resource bundle.
*/
public List getMsgs() {
return new ArrayList(msgs);
}
/**
* Handles InvocationTargetExceptions.
*
* @param e the exception.
* @param classname the class on which the method was trying
* to be invoked.
* @param methodName the name of the method trying to be invoked.
* @return the exception.
*/
public synchronized Throwable invocationTargetException
(InvocationTargetException e,
String classname,
String methodName) {
Throwable t = e.getTargetException();
if (t != null) {
if (t instanceof OutOfMemoryError) {
error("out_of_memory");
} else {
error("exception_thrown", "", classname, methodName, t+"");
t.printStackTrace();
}
}
return t != null ? t : e;
}
/**
* Handles an internal error.
*
* @param key key of the message to use.
* @param t exception thrown.
*/
public synchronized void internalError(String key, Throwable t) {
internalError(key, "", t);
}
/**
* Handles an internal error.
*
* @param key key of the message to use.
* @param s0 first argument in the message.
* @param t exception thrown.
*/
public synchronized void internalError(String key, String s0, Throwable t) {
if (t instanceof InternalCompilerError) {
t = ((InternalCompilerError)t).uncaughtThrowable;
}
error(key, s0, t != null ? t.getMessage() : "");
if (t != null) t.printStackTrace();
internalError(t, null);
}
/**
* Prints an error message for key <code>key</code>
* ,and returns the number of errors.
*
* @param key key of the message.
* @return number of errors.
*/
public final int error(String key) {
printError(text(key));
return errors;
}
/**
* Prints an error message for key <code>key</code>
* and argument <code>s0</code>,
* and returns the number of errors.
*
* @param key key of the message.
* @param s0 argument to message.
* @return number of errors.
*/
public final int error(String key, String s0) {
printError(text(key,s0));
return errors;
}
/**
* Prints an error message for key <code>key</code>
* and arguments <code>s0,s1</code>,
* and returns the number of errors.
*
* @param key key of the message.
* @param s0 argument to message.
* @param s1 argument to message.
* @return number of errors.
*/
public final int error(String key, String s0, String s1) {
printError(text(key,s0,s1));
return errors;
}
/**
* Prints an error message for key <code>key</code>
* and arguments <code>s0,s1,s2</code>,
* and returns the number of errors.
*
* @param key key of the message.
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
* @return number of errors.
*/
public final int error(String key, String s0, String s1,
String s2) {
printError(text(key,s0,s1,s2));
return errors;
}
/**
* Prints an error message for key <code>key</code>
* and arguments <code>s0,s1,s2,cookieMonster</code>,
* and returns the number of errors.
*
* @param key key of the message.
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
* @param cookieMonster argument to message.
* @return number of errors.
*/
public final int error(String key, String s0, String s1,
String s2, String cookieMonster) {
printError(text(key,s0,s1,s2,cookieMonster));
return errors;
}
/**
* Handles the thrown exception <code>t</code>
* with message key <code>key</code>, and returns
* the number of errors.
*
* @param t thrown exception.
* @param key message key.
* @return number of errors.
*/
public final int ex(Throwable t, String key) {
error(key);
if (t != null) t.printStackTrace();
return errors;
}
/**
* Handles the thrown exception <code>t</code>
* with message key <code>key</code> and
* argument <code>s0</code>, and returns
* the number of errors.
*
* @param t thrown exception.
* @param key message key.
* @param s0 argument to message.
* @return number of errors.
*/
public final int ex(Throwable t, String key, String s0) {
error(key,s0);
if (t != null) t.printStackTrace();
return errors;
}
/**
* Handles the thrown exception <code>t</code>
* with message key <code>key</code> and
* arguments <code>s0,s1</code>, and returns
* the number of errors.
*
* @param t thrown exception.
* @param key message key.
* @param s0 argument to message.
* @param s1 argument to message.
* @return number of errors.
*/
public final int ex(Throwable t, String key, String s0, String s1) {
error(key,s0,s1);
if (t != null) t.printStackTrace();
return errors;
}
/**
* Handles the thrown exception <code>t</code>
* with message key <code>key</code> and
* arguments <code>s0,s1,s2</code>, and returns
* the number of errors.
*
* @param t thrown exception.
* @param key message key.
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
* @return number of errors.
*/
public final int ex(Throwable t, String key, String s0, String s1,
String s2) {
error(key,s0,s1,s2);
if (t != null) t.printStackTrace();
return errors;
}
/**
* Handles the thrown exception <code>t</code>
* with message key <code>key</code> and
* arguments <code>s0,s1,s2,snuffulufugus</code>, and returns
* the number of errors.
*
* @param t thrown exception.
* @param key message key.
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
* @param snuffulufugus argument to message.
* @return number of errors.
*/
public final int ex(Throwable t, String key, String s0, String s1,
String s2, String snuffulufugus) {
error(key,s0,s1,s2,snuffulufugus);
if (t != null) t.printStackTrace();
return errors;
}
/**
* Prints the warning with key <code>key</code>
* and returns the number of warnings.
*
* @param key message key.
* @return number of warnings.
*/
public final int warning(String key) {
printWarning(text(key));
return warnings;
}
/**
* Prints the warning with key <code>key</code> and
* argument <code>s0</code>,
* and returns the number of warnings.
*
* @param key message key.
* @param s0 argument to message.
* @return number of warnings.
*/
public final int warning(String key, String s0) {
printWarning(text(key,s0));
return warnings;
}
/**
* Prints the warning with key <code>key</code> and
* arguments <code>s0,s1</code>,
* and returns the number of warnings.
*
* @param key message key.
* @param s0 argument to message.
* @param s1 argument to message.
* @return number of warnings.
*/
public final int warning(String key, String s0, String s1) {
printWarning(text(key,s0,s1));
return warnings;
}
/**
* Prints the warning with key <code>key</code> and
* arguments <code>s0,s1,s2</code>,
* and returns the number of warnings.
*
* @param key message key.
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
* @return number of warnings.
*/
public final int warning(String key, String s0, String s1,
String s2) {
printWarning(text(key,s0,s1,s2));
return warnings;
}
/**
* Prints the warning with key <code>key</code> and
* arguments <code>s0,s1,s2,josefStalin</code>,
* and returns the number of warnings.
*
* @param key message key.
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
* @param josefStalin argument to message.
* @return number of warnings.
*/
public final int warning(String key, String s0, String s1,
String s2, String josefStalin) {
printWarning(text(key,s0,s1,s2,josefStalin));
return warnings;
}
/**
* Print a notice with message key <code>key</code>.
*
* @param key message key.
*/
public final void notice(String key) {
printNotice(text(key));
}
/**
* Print a notice with message key <code>key</code>
* and argument <code>s0</code>.
*
* @param key message key.
* @param s0 argument to message.
*/
public final void notice(String key, String s0) {
printNotice(text(key,s0));
}
/**
* Print a notice with message key <code>key</code>
* and arguments <code>s0,s1</code>.
*
* @param key message key.
* @param s0 argument to message.
* @param s1 argument to message.
*/
public final void notice(String key, String s0, String s1) {
printNotice(text(key,s0,s1));
}
/**
* Print a notice with message key <code>key</code>
* and arguments <code>s0,s1,s2</code>.
*
* @param key message key.
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
*/
public final void notice(String key, String s0, String s1,
String s2) {
printNotice(text(key,s0,s1,s2));
}
/**
* Print a notice with message key <code>key</code>
* and arguments <code>s0,s1,s2,bigbird</code>.
*
* @param key message key.
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
* @param bigbird argument to message.
*/
public final void notice(String key, String s0, String s1,
String s2, String bigbird) {
printNotice(text(key,s0,s1,s2,bigbird));
}
/**
* Returns the String for message key <code>key</code>.
*
* @return String for message
* key <code>key</code>.
*/
protected final String text(String key) {
return text(key, "");
}
/**
* Returns the String for message key <code>key</code>
* and argument <code>s0</code>
*
* @param s0 argument to message.
* @return String for message
* key <code>key</code>.
*/
protected final String text(String key, String s0) {
return text(key, s0, "");
}
/**
* Returns the String for message key <code>key</code>
* and arguments <code>s0,s1</code>
*
* @param s0 argument to message.
* @param s1 argument to message.
* @return String for message
* key <code>key</code>.
*/
protected final String text(String key, String s0, String s1) {
return text(key, s0, s1, "");
}
/**
* Returns the String for message key <code>key</code>
* and arguments <code>s0,s1,s2</code>
*
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
* @return String for message
* key <code>key</code>.
*/
protected final String text(String key, String s0, String s1,
String s2) {
return text(key, s0, s1, s2, "");
}
/**
* Returns the String for message key <code>key</code>
* and arguments <code>s0,s1,s2,oscarTheGrouch</code>
*
* @param s0 argument to message.
* @param s1 argument to message.
* @param s2 argument to message.
* @param oscarTheGrouch argument to message.
* @return String for message
* key <code>key</code>.
*/
protected final String text(String key, String s0, String s1,
String s2, String oscarTheGrouch) {
return text(key, new String[]{s0,s1,s2,oscarTheGrouch});
}
/**
* Returns the String for the message key <code>key</code>
* with arguments contained in <code>args</code>.
*
* @param key message key.
* @param args array of arguments to substitute.
* @return String for message with key
* <code>key</code> and arguments
* <code>args</code>
*/
protected final String text(String key, String[] args) {
String msg = MessageFormat.format(string(key), args);
msgs.add(msg);
return msg;
}
/**
* Returns the String with message <code>key</code>.
*
* @param key message key.
* @return String for message with key <code>key</code>.
*/
protected final String string(String key) {
keys.add(key);
try {
return bundle.getString(key);
} catch (MissingResourceException e) {
throw new Error("Can't find " + key + " in " + bundle);
}
}
PrintWriter getErr() {
return err;
}
PrintWriter getOut() {
return out;
}
}
|