comparison graal/com.oracle.graal.debug/src/com/oracle/graal/debug/LogStream.java @ 19510:1cde96b96673

Fixed code format issues.
author Roland Schatz <roland.schatz@oracle.com>
date Thu, 19 Feb 2015 16:15:56 +0100
parents 5e3d1a68664e
children
comparison
equal deleted inserted replaced
19508:8c7536965c95 19510:1cde96b96673
24 24
25 import java.io.*; 25 import java.io.*;
26 26
27 /** 27 /**
28 * A utility for printing compiler debug and informational output to an output stream. 28 * A utility for printing compiler debug and informational output to an output stream.
29 * 29 *
30 * A {@link LogStream} instance maintains an internal buffer that is flushed to the underlying 30 * A {@link LogStream} instance maintains an internal buffer that is flushed to the underlying
31 * output stream every time one of the {@code println} methods is invoked, or a newline character ( 31 * output stream every time one of the {@code println} methods is invoked, or a newline character (
32 * {@code '\n'}) is written. 32 * {@code '\n'}) is written.
33 * 33 *
34 * All of the {@code print} and {@code println} methods return the {code LogStream} instance on 34 * All of the {@code print} and {@code println} methods return the {code LogStream} instance on
35 * which they were invoked. This allows chaining of these calls to mitigate use of String 35 * which they were invoked. This allows chaining of these calls to mitigate use of String
36 * concatenation by the caller. 36 * concatenation by the caller.
37 * 37 *
38 * A {@code LogStream} maintains a current {@linkplain #indentationLevel() indentation} level. Each 38 * A {@code LogStream} maintains a current {@linkplain #indentationLevel() indentation} level. Each
39 * line of output written to this stream has {@code n} spaces prefixed to it where {@code n} is the 39 * line of output written to this stream has {@code n} spaces prefixed to it where {@code n} is the
40 * value that would be returned by {@link #indentationLevel()} when the first character of a new 40 * value that would be returned by {@link #indentationLevel()} when the first character of a new
41 * line is written. 41 * line is written.
42 * 42 *
43 * A {@code LogStream} maintains a current {@linkplain #position() position} for the current line 43 * A {@code LogStream} maintains a current {@linkplain #position() position} for the current line
44 * being written. This position can be advanced to a specified position by 44 * being written. This position can be advanced to a specified position by
45 * {@linkplain #fillTo(int, char) filling} this stream with a given character. 45 * {@linkplain #fillTo(int, char) filling} this stream with a given character.
46 */ 46 */
47 public class LogStream { 47 public class LogStream {
85 */ 85 */
86 public static final String LINE_SEPARATOR = System.getProperty("line.separator"); 86 public static final String LINE_SEPARATOR = System.getProperty("line.separator");
87 87
88 /** 88 /**
89 * Creates a new log stream. 89 * Creates a new log stream.
90 * 90 *
91 * @param os the underlying output stream to which prints are sent 91 * @param os the underlying output stream to which prints are sent
92 */ 92 */
93 public LogStream(OutputStream os) { 93 public LogStream(OutputStream os) {
94 ps = os instanceof PrintStream ? (PrintStream) os : new PrintStream(os); 94 ps = os instanceof PrintStream ? (PrintStream) os : new PrintStream(os);
95 lineBuffer = new StringBuilder(100); 95 lineBuffer = new StringBuilder(100);
96 } 96 }
97 97
98 /** 98 /**
99 * Creates a new log stream that shares the same {@linkplain #ps output stream} as a given 99 * Creates a new log stream that shares the same {@linkplain #ps output stream} as a given
100 * {@link LogStream}. 100 * {@link LogStream}.
101 * 101 *
102 * @param log a LogStream whose output stream is shared with this one 102 * @param log a LogStream whose output stream is shared with this one
103 */ 103 */
104 public LogStream(LogStream log) { 104 public LogStream(LogStream log) {
105 ps = log.ps; 105 ps = log.ps;
106 lineBuffer = new StringBuilder(100); 106 lineBuffer = new StringBuilder(100);
145 } 145 }
146 } 146 }
147 147
148 /** 148 /**
149 * Gets the current column position of this log stream. 149 * Gets the current column position of this log stream.
150 * 150 *
151 * @return the current column position of this log stream 151 * @return the current column position of this log stream
152 */ 152 */
153 public int position() { 153 public int position() {
154 return lineBuffer == null ? 0 : lineBuffer.length(); 154 return lineBuffer == null ? 0 : lineBuffer.length();
155 155
156 } 156 }
157 157
158 /** 158 /**
159 * Gets the current indentation level for this log stream. 159 * Gets the current indentation level for this log stream.
160 * 160 *
161 * @return the current indentation level for this log stream. 161 * @return the current indentation level for this log stream.
162 */ 162 */
163 public int indentationLevel() { 163 public int indentationLevel() {
164 return indentationLevel; 164 return indentationLevel;
165 } 165 }
166 166
167 /** 167 /**
168 * Adjusts the current indentation level of this log stream. 168 * Adjusts the current indentation level of this log stream.
169 * 169 *
170 * @param delta 170 * @param delta
171 */ 171 */
172 public void adjustIndentation(int delta) { 172 public void adjustIndentation(int delta) {
173 if (delta < 0) { 173 if (delta < 0) {
174 indentationLevel = Math.max(0, indentationLevel + delta); 174 indentationLevel = Math.max(0, indentationLevel + delta);
200 } 200 }
201 201
202 /** 202 /**
203 * Advances this stream's {@linkplain #position() position} to a given position by repeatedly 203 * Advances this stream's {@linkplain #position() position} to a given position by repeatedly
204 * appending a given character as necessary. 204 * appending a given character as necessary.
205 * 205 *
206 * @param position the position to which this stream's position will be advanced 206 * @param position the position to which this stream's position will be advanced
207 * @param filler the character used to pad the stream 207 * @param filler the character used to pad the stream
208 */ 208 */
209 public LogStream fillTo(int position, char filler) { 209 public LogStream fillTo(int position, char filler) {
210 if (ps != null) { 210 if (ps != null) {
216 return this; 216 return this;
217 } 217 }
218 218
219 /** 219 /**
220 * Writes a boolean value to this stream as {@code "true"} or {@code "false"}. 220 * Writes a boolean value to this stream as {@code "true"} or {@code "false"}.
221 * 221 *
222 * @param b the value to be printed 222 * @param b the value to be printed
223 * @return this {@link LogStream} instance 223 * @return this {@link LogStream} instance
224 */ 224 */
225 public LogStream print(boolean b) { 225 public LogStream print(boolean b) {
226 if (ps != null) { 226 if (ps != null) {
231 } 231 }
232 232
233 /** 233 /**
234 * Writes a boolean value to this stream followed by a {@linkplain #LINE_SEPARATOR line 234 * Writes a boolean value to this stream followed by a {@linkplain #LINE_SEPARATOR line
235 * separator}. 235 * separator}.
236 * 236 *
237 * @param b the value to be printed 237 * @param b the value to be printed
238 * @return this {@link LogStream} instance 238 * @return this {@link LogStream} instance
239 */ 239 */
240 public LogStream println(boolean b) { 240 public LogStream println(boolean b) {
241 if (ps != null) { 241 if (ps != null) {
246 return this; 246 return this;
247 } 247 }
248 248
249 /** 249 /**
250 * Writes a character value to this stream. 250 * Writes a character value to this stream.
251 * 251 *
252 * @param c the value to be printed 252 * @param c the value to be printed
253 * @return this {@link LogStream} instance 253 * @return this {@link LogStream} instance
254 */ 254 */
255 public LogStream print(char c) { 255 public LogStream print(char c) {
256 if (ps != null) { 256 if (ps != null) {
266 } 266 }
267 267
268 /** 268 /**
269 * Writes a character value to this stream followed by a {@linkplain #LINE_SEPARATOR line 269 * Writes a character value to this stream followed by a {@linkplain #LINE_SEPARATOR line
270 * separator}. 270 * separator}.
271 * 271 *
272 * @param c the value to be printed 272 * @param c the value to be printed
273 * @return this {@link LogStream} instance 273 * @return this {@link LogStream} instance
274 */ 274 */
275 public LogStream println(char c) { 275 public LogStream println(char c) {
276 if (ps != null) { 276 if (ps != null) {
281 return this; 281 return this;
282 } 282 }
283 283
284 /** 284 /**
285 * Prints an int value. 285 * Prints an int value.
286 * 286 *
287 * @param i the value to be printed 287 * @param i the value to be printed
288 * @return this {@link LogStream} instance 288 * @return this {@link LogStream} instance
289 */ 289 */
290 public LogStream print(int i) { 290 public LogStream print(int i) {
291 if (ps != null) { 291 if (ps != null) {
295 return this; 295 return this;
296 } 296 }
297 297
298 /** 298 /**
299 * Writes an int value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator}. 299 * Writes an int value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator}.
300 * 300 *
301 * @param i the value to be printed 301 * @param i the value to be printed
302 * @return this {@link LogStream} instance 302 * @return this {@link LogStream} instance
303 */ 303 */
304 public LogStream println(int i) { 304 public LogStream println(int i) {
305 if (ps != null) { 305 if (ps != null) {
310 return this; 310 return this;
311 } 311 }
312 312
313 /** 313 /**
314 * Writes a float value to this stream. 314 * Writes a float value to this stream.
315 * 315 *
316 * @param f the value to be printed 316 * @param f the value to be printed
317 * @return this {@link LogStream} instance 317 * @return this {@link LogStream} instance
318 */ 318 */
319 public LogStream print(float f) { 319 public LogStream print(float f) {
320 if (ps != null) { 320 if (ps != null) {
325 } 325 }
326 326
327 /** 327 /**
328 * Writes a float value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator} 328 * Writes a float value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator}
329 * . 329 * .
330 * 330 *
331 * @param f the value to be printed 331 * @param f the value to be printed
332 * @return this {@link LogStream} instance 332 * @return this {@link LogStream} instance
333 */ 333 */
334 public LogStream println(float f) { 334 public LogStream println(float f) {
335 if (ps != null) { 335 if (ps != null) {
340 return this; 340 return this;
341 } 341 }
342 342
343 /** 343 /**
344 * Writes a long value to this stream. 344 * Writes a long value to this stream.
345 * 345 *
346 * @param l the value to be printed 346 * @param l the value to be printed
347 * @return this {@link LogStream} instance 347 * @return this {@link LogStream} instance
348 */ 348 */
349 public LogStream print(long l) { 349 public LogStream print(long l) {
350 if (ps != null) { 350 if (ps != null) {
354 return this; 354 return this;
355 } 355 }
356 356
357 /** 357 /**
358 * Writes a long value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator}. 358 * Writes a long value to this stream followed by a {@linkplain #LINE_SEPARATOR line separator}.
359 * 359 *
360 * @param l the value to be printed 360 * @param l the value to be printed
361 * @return this {@link LogStream} instance 361 * @return this {@link LogStream} instance
362 */ 362 */
363 public LogStream println(long l) { 363 public LogStream println(long l) {
364 if (ps != null) { 364 if (ps != null) {
369 return this; 369 return this;
370 } 370 }
371 371
372 /** 372 /**
373 * Writes a double value to this stream. 373 * Writes a double value to this stream.
374 * 374 *
375 * @param d the value to be printed 375 * @param d the value to be printed
376 * @return this {@link LogStream} instance 376 * @return this {@link LogStream} instance
377 */ 377 */
378 public LogStream print(double d) { 378 public LogStream print(double d) {
379 if (ps != null) { 379 if (ps != null) {
384 } 384 }
385 385
386 /** 386 /**
387 * Writes a double value to this stream followed by a {@linkplain #LINE_SEPARATOR line 387 * Writes a double value to this stream followed by a {@linkplain #LINE_SEPARATOR line
388 * separator}. 388 * separator}.
389 * 389 *
390 * @param d the value to be printed 390 * @param d the value to be printed
391 * @return this {@link LogStream} instance 391 * @return this {@link LogStream} instance
392 */ 392 */
393 public LogStream println(double d) { 393 public LogStream println(double d) {
394 if (ps != null) { 394 if (ps != null) {
401 401
402 /** 402 /**
403 * Writes a {@code String} value to this stream. This method ensures that the 403 * Writes a {@code String} value to this stream. This method ensures that the
404 * {@linkplain #position() position} of this stream is updated correctly with respect to any 404 * {@linkplain #position() position} of this stream is updated correctly with respect to any
405 * {@linkplain #LINE_SEPARATOR line separators} present in {@code s}. 405 * {@linkplain #LINE_SEPARATOR line separators} present in {@code s}.
406 * 406 *
407 * @param s the value to be printed 407 * @param s the value to be printed
408 * @return this {@link LogStream} instance 408 * @return this {@link LogStream} instance
409 */ 409 */
410 public LogStream print(String s) { 410 public LogStream print(String s) {
411 if (ps != null) { 411 if (ps != null) {
434 } 434 }
435 435
436 /** 436 /**
437 * Writes a {@code String} value to this stream followed by a {@linkplain #LINE_SEPARATOR line 437 * Writes a {@code String} value to this stream followed by a {@linkplain #LINE_SEPARATOR line
438 * separator}. 438 * separator}.
439 * 439 *
440 * @param s the value to be printed 440 * @param s the value to be printed
441 * @return this {@link LogStream} instance 441 * @return this {@link LogStream} instance
442 */ 442 */
443 public LogStream println(String s) { 443 public LogStream println(String s) {
444 if (ps != null) { 444 if (ps != null) {
448 return this; 448 return this;
449 } 449 }
450 450
451 /** 451 /**
452 * Writes a formatted string to this stream. 452 * Writes a formatted string to this stream.
453 * 453 *
454 * @param format a format string as described in {@link String#format(String, Object...)} 454 * @param format a format string as described in {@link String#format(String, Object...)}
455 * @param args the arguments to be formatted 455 * @param args the arguments to be formatted
456 * @return this {@link LogStream} instance 456 * @return this {@link LogStream} instance
457 */ 457 */
458 public LogStream printf(String format, Object... args) { 458 public LogStream printf(String format, Object... args) {
462 return this; 462 return this;
463 } 463 }
464 464
465 /** 465 /**
466 * Writes a {@linkplain #LINE_SEPARATOR line separator} to this stream. 466 * Writes a {@linkplain #LINE_SEPARATOR line separator} to this stream.
467 * 467 *
468 * @return this {@code LogStream} instance 468 * @return this {@code LogStream} instance
469 */ 469 */
470 public LogStream println() { 470 public LogStream println() {
471 if (ps != null) { 471 if (ps != null) {
472 indent(); 472 indent();