1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3
* Copyright (C) 1998-2001 Gerwin Klein <lsf@jflex.de> *
4
* All rights reserved. *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License. See the file *
8
* COPYRIGHT for more information. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License along *
16
* with this program; if not, write to the Free Software Foundation, Inc., *
17
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25
import java.awt.TextArea;
29
* In this class all output to the java console is filtered.
31
* Use the switches VERBOSE, TIME and DUMP at compile time to determine
32
* the verbosity of JFlex output. There is no switch for
33
* suppressing error messages. VERBOSE and TIME can be overridden
34
* by command line paramters.
36
* Redirects output to a TextArea in GUI mode.
38
* Counts error and warning messages.
42
* VERBOSE should be switched on in all normal cases.
43
* It is used for standard progress messages to the user.
45
* TIME can be set to true for performance measurements if
46
* time statistics for the different stages of generation
49
* DUMP this one gives you all the information you want (or not).
50
* BUT: prepare to wait.
51
* If only dump-information from specific classes is
52
* needed, compile all classes with DUMP=false first,
53
* then recompile this class and all the classes that
54
* are to dump their information with DUMP=true.
58
* @author Gerwin Klein
59
* @version JFlex 1.3.5, $Revision: 1.29 $, $Date: 2001/10/08 10:08:03 $
61
public final class Out implements ErrorMessages {
63
/** platform dependent newline sequence */
64
public static final String NL = System.getProperty("line.separator");
67
* If VERBOSE is false, no progress output will be generated
69
public static boolean VERBOSE = true;
72
* If TIME is true, jflex will print time statistics about the generation process
74
public static boolean TIME = false;
77
* If DUMP is true, you will be flooded with information (e.g. dfa tables).
79
public static boolean DUMP = false;
82
* If DOT is true, jflex will write graphviz .dot files for generated automata
84
public static boolean DOT = false;
87
* If DEBUG is true, additional verbose debug information is produced
89
public final static boolean DEBUG = false;
91
/** count total warnings */
92
public static int warnings;
94
/** count total errors */
95
public static int errors;
98
private static StdOutWriter out = new StdOutWriter();
102
* Switches to GUI mode if <code>text</code> is not <code>null</code>
104
* @param text the message TextArea of the JFlex GUI
106
public static void setGUIMode(TextArea text) {
107
out.setGUIMode(text);
111
* All parts of JFlex, that want to report something about
112
* time statistic should use this method for their output.
114
* @param message the message to be printed
116
public static void time(String message) {
117
if (TIME) out.println(message);
122
* All parts of JFlex, that want to report generation progress
123
* should use this method for their output.
125
* @param message the message to be printed
127
public static void println(String message) {
128
if (VERBOSE) out.println(message);
133
* All parts of JFlex, that want to report generation progress
134
* should use this method for their output.
136
* @param message the message to be printed
138
public static void print(String message) {
139
if (VERBOSE) out.print(message);
143
* Dump debug information to System.out
147
* <code>if (Out.DEBUG) Out.debug(message)</code>
149
* to save performance during normal operation (when DEBUG
152
public static void debug(String message) {
153
if (DEBUG) System.out.println(message);
158
* All parts of JFlex, that want to provide dump information
159
* should use this method for their output.
161
* @message the message to be printed
163
public static void dump(String message) {
164
if (DUMP) out.println(message);
169
* All parts of JFlex, that want to report error messages
170
* should use this method for their output.
172
* @message the message to be printed
174
private static void err(String message) {
175
out.println(message);
180
* throws a GeneratorException if there are any errors recorded
182
public static void checkErrors() {
183
if (errors > 0) throw new GeneratorException();
188
* print error and warning statistics
190
public static void statistics() {
191
StringBuffer line = new StringBuffer(errors+" error");
192
if (errors != 1) line.append("s");
194
line.append(", "+warnings+" warning");
195
if (warnings != 1) line.append("s");
198
err(line.toString());
203
* reset error and warning counters
205
public static void resetCounters() {
212
* print a warning without position information
214
* @param message the warning message
216
public static void warning(String message) {
219
err(NL+"Warning : "+message);
224
* print a warning with line information
226
* @param message code of the warning message
227
* @param line the line information
231
public static void warning(int message, int line) {
234
String msg = NL+"Warning";
235
if (line > 0) msg = msg+" in line "+(line+1);
237
err(msg+": "+messages[message]);
242
* print warning message with location information
244
* @param file the file the warning is issued for
245
* @param message the code of the message to print
246
* @param line the line number of the position
247
* @param column the column of the position
249
public static void warning(File file, int message, int line, int column) {
251
String msg = NL+"Warning";
252
if (file != null) msg += " in file \""+file+"\"";
253
if (line >= 0) msg = msg+" (line "+(line+1)+")";
256
err(msg+": "+NL+messages[message]);
258
catch (ArrayIndexOutOfBoundsException e) {
266
showPosition(file, line, column);
268
showPosition(file, line);
274
* print error message (string)
276
* @param message the message to print
278
public static void error(String message) {
285
* print error message (code)
287
* @param message the code of the error message
291
public static void error(int message) {
293
err(NL+"Error: "+messages[message] );
298
* IO error message for a file (displays file
299
* name in parentheses).
301
* @param message the code of the error message
302
* @param file the file it occurred for
304
public static void error(int message, File file) {
306
err(NL+"Error: "+messages[message]+" ("+file+")");
311
* print error message with location information
313
* @param file the file the error occurred for
314
* @param message the code of the error message to print
315
* @param line the line number of error position
316
* @param column the column of error position
318
public static void error(File file, int message, int line, int column) {
320
String msg = NL+"Error";
321
if (file != null) msg += " in file \""+file+"\"";
322
if (line >= 0) msg = msg+" (line "+(line+1)+")";
325
err(msg+": "+NL+messages[message]);
327
catch (ArrayIndexOutOfBoundsException e) {
335
showPosition(file, line, column);
337
showPosition(file, line);
343
* prints a line of a file with marked position.
345
* @param file the file of which to show the line
346
* @param line the line to show
347
* @param column the column in which to show the marker
349
public static void showPosition(File file, int line, int column) {
351
String ln = getLine(file, line);
355
if (column < 0) return;
358
for (int i = 0; i < column; i++) t = " "+t;
363
catch (IOException e) {
364
/* silently ignore IO errors, don't show anything */
370
* print a line of a file
372
* @param file the file to show
373
* @param line the line number
375
public static void showPosition(File file, int line) {
377
String ln = getLine(file, line);
378
if (ln != null) err(ln);
380
catch (IOException e) {
381
/* silently ignore IO errors, don't show anything */
387
* get one line from a file
389
* @param file the file to read
390
* @param line the line number to get
392
* @throw IOException if any error occurs
394
private static String getLine(File file, int line) throws IOException {
395
BufferedReader reader = new BufferedReader(new FileReader(file));
399
for (int i = 0; i <= line; i++)
400
msg = reader.readLine();
409
* Print system information (e.g. in case of unexpected exceptions)
411
public static void printSystemInfo() {
412
err("Java version: "+System.getProperty("java.version"));
413
err("Runtime name: "+System.getProperty("java.runtime.name"));
414
err("Vendor: "+System.getProperty("java.vendor"));
415
err("VM version: "+System.getProperty("java.vm.version"));
416
err("VM vendor: "+System.getProperty("java.vm.vendor"));
417
err("VM name: "+System.getProperty("java.vm.name"));
418
err("VM info: "+System.getProperty("java.vm.info"));
419
err("OS name: "+System.getProperty("os.name"));
420
err("OS arch: "+System.getProperty("os.arch"));
421
err("OS version: "+System.getProperty("os.version"));
422
err("Encoding: "+System.getProperty("file.encoding"));
423
err("JFlex version: "+Main.version);
428
* Request a bug report for an unexpected Exception/Error.
430
public static void requestBugReport(Error e) {
431
err("An unexpected error occurred. Please send a report of this to");
432
err("<bugs@jflex.de> and include the following information:");
436
e.printStackTrace(out);
438
err("Please also include a specification (as small as possible)");
439
err("that triggered this error. You may also want to check at");
440
err("http://www.jflex.de if there is a newer version available");
441
err("that doesn't have this problem");
443
err("Thanks for your support.");