mjc

org.multijava.mjc
Class Debug

java.lang.Object
  extended byorg.multijava.mjc.Debug

public class Debug
extends Object

This singleton class localizes the reporting of debugging information. It includes features like indenting to match depth of the call stack and prefixes to indicate what section of code is being executed. It also allows users to specify an output stream other than standard out (e.g., a file).


Field Summary
private static String BLANK
           
private static boolean debug
           
private static int indent
           
private static BreakIterator lineBreaker
           
private static ArrayList lines
           
private static int lineWidth
           
private static long messageMask
           
private static Map metaDebugMap
           
private static PrintStream out
           
private static String prefix
           
private static Map profileMap
           
static PrintStream stderr
          A cache of System.err so we can hack around code that uses System.setErr()
private static String TAB
           
private static int TAB_LENGTH
           
 
Constructor Summary
private Debug()
          Overrides the default initialize so this class cannot be instantiated.
 
Method Summary
static void breakMe()
          This method does nothing.
static void close()
          Closes a debugging session and print the indent stack if the outdents did not match the indents.
static void initialize()
          Resets the debug reporting methods to turn off debugging and use standard error as the output stream
static void initialize(boolean debug)
          Resets the debug reporting methods to use standard error as the output stream.
static void initialize(boolean debug, PrintStream out)
          Resets the debug reporting methods.
static boolean isDebugOn()
          Indicates whether debugging output is currently activated.
static void msg(String msg)
          Writes the given debugging message to the debugging output stream.
static void msg(MessageDescription msg)
          Writes the given debugging message, without parameter substitution, to the debugging output stream.
static void msg(MessageDescription msg, Object p0)
          Writes the given debugging message, with appropriate parameter substitution, to the debugging output stream.
static void msg(MessageDescription msg, Object p0, Object p1)
          Writes the given debugging message, with appropriate parameter substitution, to the debugging output stream.
static void msg(MessageDescription msg, Object[] ps)
          Writes the given debugging message, with appropriate parameter substitution, to the debugging output stream.
private static void output(String fullMsg)
          Writes the given string to the debug output stream handling indenting, prefixes and line wrapping.
static long profileEnd(Object profileID)
          Finishes profiling for a block of code with the given profileID object by returning the time (in milliseconds) since profileStart was called for the given ID.
static String profileEndAsString(Object profileID)
          Finishes profiling for a block of code with the given profileID object by returning a String of the form (profileID.toString + "took x ms") where x is the time (in milliseconds) since profileStart was called for the given ID.
static void profileStart(Object profileID)
          Begins profiling for a block of code with the given profileID object.
static void recordMessage(String msg)
          Appends the given string to a file named MultiJavaDebugMessages.txt in the current temporary directory, creating the file if it does not exist.
private static void registerIndent(Object caller, String msg)
           
private static void registerOutdent(Object caller)
           
static void setPrefix(String prefix)
          Sets the prefix that is written before each debugging message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

private static boolean debug

out

private static PrintStream out

prefix

private static String prefix

indent

private static int indent

lineWidth

private static int lineWidth

messageMask

private static long messageMask

TAB

private static final String TAB

BLANK

private static final String BLANK

TAB_LENGTH

private static final int TAB_LENGTH

lineBreaker

private static final BreakIterator lineBreaker

lines

private static final ArrayList lines

metaDebugMap

private static final Map metaDebugMap

profileMap

private static final Map profileMap

stderr

public static final PrintStream stderr
A cache of System.err so we can hack around code that uses System.setErr()

Constructor Detail

Debug

private Debug()
Overrides the default initialize so this class cannot be instantiated.

Method Detail

initialize

public static void initialize()
Resets the debug reporting methods to turn off debugging and use standard error as the output stream


initialize

public static void initialize(boolean debug)
Resets the debug reporting methods to use standard error as the output stream.

Parameters:
debug - indicates whether debug reporting methods should report

initialize

public static void initialize(boolean debug,
                              PrintStream out)
Resets the debug reporting methods.

Parameters:
debug - indicates whether debug reporting methods should report
out - the stream to write debug messages to

setPrefix

public static void setPrefix(String prefix)
Sets the prefix that is written before each debugging message. This is useful, for example, in differentiating the debugging messages from different compilation passes.

Parameters:
prefix - the prefix that should precede all output lines

isDebugOn

public static boolean isDebugOn()
Indicates whether debugging output is currently activated.

Returns:
a flag indicating whether debugging output is currently activated

close

public static void close()
Closes a debugging session and print the indent stack if the outdents did not match the indents.


msg

public static void msg(String msg)
Writes the given debugging message to the debugging output stream.

Parameters:
msg - the string to write

msg

public static void msg(MessageDescription msg)
Writes the given debugging message, without parameter substitution, to the debugging output stream.

Parameters:
msg - the MessageDescription to write

msg

public static void msg(MessageDescription msg,
                       Object p0)
Writes the given debugging message, with appropriate parameter substitution, to the debugging output stream.

Parameters:
msg - the MessageDescription to write
p0 - the object to substitute for {0} in msg

msg

public static void msg(MessageDescription msg,
                       Object p0,
                       Object p1)
Writes the given debugging message, with appropriate parameter substitution, to the debugging output stream.

Parameters:
msg - the MessageDescription to write
p0 - the object to substitute for {0} in msg
p1 - the object to substitute for {1} in msg

msg

public static void msg(MessageDescription msg,
                       Object[] ps)
Writes the given debugging message, with appropriate parameter substitution, to the debugging output stream.

Parameters:
msg - the MessageDescription to write
ps - the objects to substitute msg

output

private static void output(String fullMsg)
Writes the given string to the debug output stream handling indenting, prefixes and line wrapping.

Parameters:
fullMsg - the String to write

profileStart

public static void profileStart(Object profileID)
Begins profiling for a block of code with the given profileID object.

See Also:
profileEnd( Object )

profileEnd

public static long profileEnd(Object profileID)
Finishes profiling for a block of code with the given profileID object by returning the time (in milliseconds) since profileStart was called for the given ID.

See Also:
profileStart( Object )

profileEndAsString

public static String profileEndAsString(Object profileID)
Finishes profiling for a block of code with the given profileID object by returning a String of the form (profileID.toString + "took x ms") where x is the time (in milliseconds) since profileStart was called for the given ID.

See Also:
profileStart( Object )

recordMessage

public static void recordMessage(String msg)
Appends the given string to a file named MultiJavaDebugMessages.txt in the current temporary directory, creating the file if it does not exist.


registerIndent

private static void registerIndent(Object caller,
                                   String msg)

registerOutdent

private static void registerOutdent(Object caller)

breakMe

public static void breakMe()
This method does nothing. It is a hack for using jdb. Sometimes jdb won't set a break point, complaining "no code at line x" when you know good and well that there is code there, dammit. So, set a break point on this (stop in org.multijava.mjc.Debug.breakMe()) and add a call Debug.breakMe() where you want to break. This also supports conditional breaks. Cool, huh?


mjc

mjc is Copyright (C) 2000-2004 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. mjc is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.