Package org.spongepowered.asm.util
Class PrettyPrinter
- java.lang.Object
-
- org.spongepowered.asm.util.PrettyPrinter
-
public class PrettyPrinter extends java.lang.ObjectPrints information in a pretty box
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPrettyPrinter.AlignmentTable column alignmentstatic interfacePrettyPrinter.IPrettyPrintableInterface for object which supports printing to pretty printer
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringkvFormatprotected intkvKeyWidthKey/value key widthprotected intwidthBox with (adapts to contents)protected intwrapWidthWrap width used when an explicit wrap width is not specified
-
Constructor Summary
Constructors Constructor Description PrettyPrinter()PrettyPrinter(int width)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PrettyPrinteradd()Adds a blank line to the outputPrettyPrinteradd(java.lang.Object object)Adds the specified object to the outputPrettyPrinteradd(java.lang.Object[] array)Add elements of the array to the output, one per linePrettyPrinteradd(java.lang.Object[] array, java.lang.String format)Add elements of the array to the output, one per linePrettyPrinteradd(java.lang.Object object, int indent)Adds the specified object to the outputPrettyPrinteradd(java.lang.StackTraceElement[] stackTrace, int indent)Print a formatted representation of the specified stack trace with the specified indentPrettyPrinteradd(java.lang.String string)Adds a string line to the outputPrettyPrinteradd(java.lang.String format, java.lang.Object... args)Adds a formatted line to the outputPrettyPrinteradd(java.lang.Throwable th)Print a formatted representation of the specified throwable with the default indent (4)PrettyPrinteradd(java.lang.Throwable th, int indent)Print a formatted representation of the specified throwable with the specified indentPrettyPrinteradd(java.util.Map<?,?> map)Add all values of the specified map to this printer as key/value pairsPrettyPrinteradd(PrettyPrinter.IPrettyPrintable printable)Adds a pretty-printable object to the output, the object is responsible for adding its own representation to this printerPrettyPrinteraddIndexed(java.lang.Object[] array)Add elements of the array to the output, one per line, with array indicesPrettyPrinteraddWithIndices(java.util.Collection<?> c)Add elements of the collection to the output, one per line, with indicesPrettyPrinteraddWrapped(int width, java.lang.String format, java.lang.Object... args)Adds a formatted line to the output, and attempts to wrap the line content to the specified widthPrettyPrinteraddWrapped(java.lang.String format, java.lang.Object... args)Adds a formatted line to the output, and attempts to wrap the line content to the current wrap widthPrettyPrintercentre()Centre the last line addedstatic voiddumpStack()Convenience method, alternative to using Thread.dumpStack which prints to stderr in pretty-printed format.PrettyPrinterhr()Adds a horizontal rule to the outputPrettyPrinterhr(char ruleChar)Adds a horizontal rule of the specified char to the outputPrettyPrinterkv(java.lang.String key, java.lang.Object value)Add a key/value pair to the outputPrettyPrinterkv(java.lang.String key, java.lang.String format, java.lang.Object... args)Add a formatted key/value pair to the outputPrettyPrinterkvWidth(int width)Set the minimum key display widthPrettyPrinterlog(ILogger logger)Write this printer to the specified logger atLevel.INFOPrettyPrinterlog(ILogger logger, Level level)Write this printer to the specified loggerPrettyPrinterlog(Level level)Write this printer to the specified logger atLevel.INFOPrettyPrinterprint()Print this printer to stderrPrettyPrinterprint(java.io.PrintStream stream)Print this printer to the specified outputstatic voidprint(java.lang.Throwable th)Convenience methods, pretty-prints the specified throwable to stderrPrettyPrinterspacing(int spacing)Set the column spacing for the current table.PrettyPrintertable()Begin a new table with no header and adaptive column widthsPrettyPrintertable(java.lang.Object... format)Begin a new table with the specified format.PrettyPrintertable(java.lang.String... titles)Begin a new table with the specified headers and adaptive column widthsPrettyPrinterth()Print the current table header.PrettyPrintertr(java.lang.Object... args)Print a table row with the specified values.PrettyPrintertrace()Outputs this printer to stderr and to a logger decorated with the calling class name with levelLevel.DEBUGPrettyPrintertrace(java.io.PrintStream stream)Outputs this printer to the specified stream and to a logger decorated with the calling class name with levelLevel.DEBUGPrettyPrintertrace(java.io.PrintStream stream, java.lang.String logger)Outputs this printer to the specified stream and to a logger with the specified name with levelLevel.DEBUGPrettyPrintertrace(java.io.PrintStream stream, java.lang.String logger, Level level)Outputs this printer to the specified stream and to a logger with the specified name at the specified levelPrettyPrintertrace(java.io.PrintStream stream, ILogger logger)Outputs this printer to the specified stream and to the supplied logger with levelLevel.DEBUGPrettyPrintertrace(java.io.PrintStream stream, ILogger logger, Level level)Outputs this printer to the specified stream and to the supplied logger with at the specified levelPrettyPrintertrace(java.io.PrintStream stream, Level level)Outputs this printer to the specified stream and to a logger decorated with the calling class name with the specified levelPrettyPrintertrace(java.lang.String logger)Outputs this printer to stderr and to a logger decorated with specified name with levelLevel.DEBUGPrettyPrintertrace(java.lang.String logger, Level level)Outputs this printer to stderr and to a logger decorated with specified name with the specified levelPrettyPrintertrace(ILogger logger)Outputs this printer to stderr and to the supplied logger with levelLevel.DEBUGPrettyPrintertrace(ILogger logger, Level level)Outputs this printer to stderr and to the supplied logger with the specified levelPrettyPrintertrace(Level level)Outputs this printer to stderr and to a logger decorated with the calling class name at the specified levelintwrapTo()Get the current wrap widthPrettyPrinterwrapTo(int wrapWidth)Set the wrap width (default 80 columns)
-
-
-
Method Detail
-
wrapTo
public PrettyPrinter wrapTo(int wrapWidth)
Set the wrap width (default 80 columns)- Parameters:
wrapWidth- new width (in characters) to wrap to- Returns:
- fluent interface
-
wrapTo
public int wrapTo()
Get the current wrap width- Returns:
- the current wrap width
-
table
public PrettyPrinter table()
Begin a new table with no header and adaptive column widths- Returns:
- fluent interface
-
table
public PrettyPrinter table(java.lang.String... titles)
Begin a new table with the specified headers and adaptive column widths- Parameters:
titles- Column titles- Returns:
- fluent interface
-
table
public PrettyPrinter table(java.lang.Object... format)
Begin a new table with the specified format. The format is specified as a sequence of values withStrings defining column titles,Integers defining column widths, andPrettyPrinter.Alignments defining column alignments. Widths and alignment specifiers should follow the relevant column title. Specify a negative value to specify the maximum width for a column (values will be truncated).For example, to specify a table with two columns of width 10:
printer.table("Column 1", 10, "Column 2", 10);A table with a column 30 characters wide and a right-aligned column 20 characters wide:
printer.table("Column 1", 30, "Column 2", 20, Alignment.RIGHT);- Parameters:
format- format string, see description- Returns:
- fluent interface
-
spacing
public PrettyPrinter spacing(int spacing)
Set the column spacing for the current table. Default = 2- Parameters:
spacing- Column spacing in characters- Returns:
- fluent interface
-
th
public PrettyPrinter th()
Print the current table header. The table header is automatically printed before the first row if not explicitly specified by calling this method.- Returns:
- fluent interface
-
tr
public PrettyPrinter tr(java.lang.Object... args)
Print a table row with the specified values. If more columns are specified than exist in the table, then the table is automatically expanded.- Parameters:
args- column values- Returns:
- fluent interface
-
add
public PrettyPrinter add()
Adds a blank line to the output- Returns:
- fluent interface
-
add
public PrettyPrinter add(java.lang.String string)
Adds a string line to the output- Parameters:
string- format string- Returns:
- fluent interface
-
add
public PrettyPrinter add(java.lang.String format, java.lang.Object... args)
Adds a formatted line to the output- Parameters:
format- format stringargs- arguments- Returns:
- fluent interface
-
add
public PrettyPrinter add(java.lang.Object[] array)
Add elements of the array to the output, one per line- Parameters:
array- Array of objects to print- Returns:
- fluent interface
-
add
public PrettyPrinter add(java.lang.Object[] array, java.lang.String format)
Add elements of the array to the output, one per line- Parameters:
array- Array of objects to printformat- Format for each row- Returns:
- fluent interface
-
addIndexed
public PrettyPrinter addIndexed(java.lang.Object[] array)
Add elements of the array to the output, one per line, with array indices- Parameters:
array- Array of objects to print- Returns:
- fluent interface
-
addWithIndices
public PrettyPrinter addWithIndices(java.util.Collection<?> c)
Add elements of the collection to the output, one per line, with indices- Parameters:
c- Collection of objects to print- Returns:
- fluent interface
-
add
public PrettyPrinter add(PrettyPrinter.IPrettyPrintable printable)
Adds a pretty-printable object to the output, the object is responsible for adding its own representation to this printer- Parameters:
printable- object to add- Returns:
- fluent interface
-
add
public PrettyPrinter add(java.lang.Throwable th)
Print a formatted representation of the specified throwable with the default indent (4)- Parameters:
th- Throwable to print- Returns:
- fluent interface
-
add
public PrettyPrinter add(java.lang.Throwable th, int indent)
Print a formatted representation of the specified throwable with the specified indent- Parameters:
th- Throwable to printindent- Indent size for stacktrace lines- Returns:
- fluent interface
-
add
public PrettyPrinter add(java.lang.StackTraceElement[] stackTrace, int indent)
Print a formatted representation of the specified stack trace with the specified indent- Parameters:
stackTrace- stack trace to printindent- Indent size for stacktrace lines- Returns:
- fluent interface
-
add
public PrettyPrinter add(java.lang.Object object)
Adds the specified object to the output- Parameters:
object- object to add- Returns:
- fluent interface
-
add
public PrettyPrinter add(java.lang.Object object, int indent)
Adds the specified object to the output- Parameters:
object- object to addindent- indent amount- Returns:
- fluent interface
-
addWrapped
public PrettyPrinter addWrapped(java.lang.String format, java.lang.Object... args)
Adds a formatted line to the output, and attempts to wrap the line content to the current wrap width- Parameters:
format- format stringargs- arguments- Returns:
- fluent interface
-
addWrapped
public PrettyPrinter addWrapped(int width, java.lang.String format, java.lang.Object... args)
Adds a formatted line to the output, and attempts to wrap the line content to the specified width- Parameters:
width- wrap width to use for this contentformat- format stringargs- arguments- Returns:
- fluent interface
-
kv
public PrettyPrinter kv(java.lang.String key, java.lang.String format, java.lang.Object... args)
Add a formatted key/value pair to the output- Parameters:
key- Keyformat- Value formatargs- Value args- Returns:
- fluent interface
-
kv
public PrettyPrinter kv(java.lang.String key, java.lang.Object value)
Add a key/value pair to the output- Parameters:
key- Keyvalue- Value- Returns:
- fluent interface
-
kvWidth
public PrettyPrinter kvWidth(int width)
Set the minimum key display width- Parameters:
width- width to set- Returns:
- fluent
-
add
public PrettyPrinter add(java.util.Map<?,?> map)
Add all values of the specified map to this printer as key/value pairs- Parameters:
map- Map with entries to add- Returns:
- fluent
-
hr
public PrettyPrinter hr()
Adds a horizontal rule to the output- Returns:
- fluent interface
-
hr
public PrettyPrinter hr(char ruleChar)
Adds a horizontal rule of the specified char to the output- Parameters:
ruleChar- character to use for the horizontal rule- Returns:
- fluent interface
-
centre
public PrettyPrinter centre()
Centre the last line added- Returns:
- fluent interface
-
trace
public PrettyPrinter trace()
Outputs this printer to stderr and to a logger decorated with the calling class name with levelLevel.DEBUG- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(Level level)
Outputs this printer to stderr and to a logger decorated with the calling class name at the specified level- Parameters:
level- Log level to write messages- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(java.lang.String logger)
Outputs this printer to stderr and to a logger decorated with specified name with levelLevel.DEBUG- Parameters:
logger- Logger name to write to- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(java.lang.String logger, Level level)
Outputs this printer to stderr and to a logger decorated with specified name with the specified level- Parameters:
logger- Logger name to write tolevel- Log level to write messages- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(ILogger logger)
Outputs this printer to stderr and to the supplied logger with levelLevel.DEBUG- Parameters:
logger- Logger to write to- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(ILogger logger, Level level)
Outputs this printer to stderr and to the supplied logger with the specified level- Parameters:
logger- Logger to write tolevel- Log level to write messages- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(java.io.PrintStream stream)
Outputs this printer to the specified stream and to a logger decorated with the calling class name with levelLevel.DEBUG- Parameters:
stream- Output stream to print to- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(java.io.PrintStream stream, Level level)
Outputs this printer to the specified stream and to a logger decorated with the calling class name with the specified level- Parameters:
stream- Output stream to print tolevel- Log level to write messages- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(java.io.PrintStream stream, java.lang.String logger)
Outputs this printer to the specified stream and to a logger with the specified name with levelLevel.DEBUG- Parameters:
stream- Output stream to print tologger- Logger name to write to- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(java.io.PrintStream stream, java.lang.String logger, Level level)
Outputs this printer to the specified stream and to a logger with the specified name at the specified level- Parameters:
stream- Output stream to print tologger- Logger name to write tolevel- Log level to write messages- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(java.io.PrintStream stream, ILogger logger)
Outputs this printer to the specified stream and to the supplied logger with levelLevel.DEBUG- Parameters:
stream- Output stream to print tologger- Logger to write to- Returns:
- fluent interface
-
trace
public PrettyPrinter trace(java.io.PrintStream stream, ILogger logger, Level level)
Outputs this printer to the specified stream and to the supplied logger with at the specified level- Parameters:
stream- Output stream to print tologger- Logger to write tolevel- Log level to write messages- Returns:
- fluent interface
-
print
public PrettyPrinter print()
Print this printer to stderr- Returns:
- fluent interface
-
print
public PrettyPrinter print(java.io.PrintStream stream)
Print this printer to the specified output- Parameters:
stream- stream to print to- Returns:
- fluent interface
-
log
public PrettyPrinter log(ILogger logger)
Write this printer to the specified logger atLevel.INFO- Parameters:
logger- logger to log to- Returns:
- fluent interface
-
log
public PrettyPrinter log(Level level)
Write this printer to the specified logger atLevel.INFO- Parameters:
level- log level- Returns:
- fluent interface
-
log
public PrettyPrinter log(ILogger logger, Level level)
Write this printer to the specified logger- Parameters:
logger- logger to log tolevel- log level- Returns:
- fluent interface
-
dumpStack
public static void dumpStack()
Convenience method, alternative to using Thread.dumpStack which prints to stderr in pretty-printed format.
-
print
public static void print(java.lang.Throwable th)
Convenience methods, pretty-prints the specified throwable to stderr- Parameters:
th- Throwable to log
-
-