com.borland.primetime.util
Class Debug

java.lang.Object
  |
  +--com.borland.primetime.util.Debug

public class Debug
extends java.lang.Object

The Debug class is used for debugging purposes (obviously). In a production build, this class is excluded by the compiler. Thus, all references to this class are removed from the compiled code. Typical usage is for testing preconditions and checks (assertions), as well as logging output to help debug the JBuilder product and addins.


Field Summary
static int count
           Common counter variable used as 'line numbers' for debug output messages.
static java.io.PrintStream out
           
 
Constructor Summary
Debug()
           
 
Method Summary
static void addTraceCategory(java.lang.Object category)
           Category based tracing and warning.
static void assert(boolean condition)
          Asserts a condition.
static void assert(boolean condition, java.lang.String description)
          Asserts a condition before a method body is run.
static void debugRect(java.awt.Graphics g, int x, int y, int width, int height)
          Paints a color-cycled hashmarked rectangle in the passed bounds.
static void enableAssert(boolean enable)
          Enables or disables the checking of conditions in precondition() and check()
static void enableOutput(boolean enable)
          Enables or disables all output of debug messages to System.err.
static void flush()
          Flushes the debug out stream buffer.
static void print(java.lang.String message)
          Prints a message to the debug out stream.
static void println(java.lang.String message)
          Prints a message (and a cr/lf) to the debug out stream.
static void printlnc(java.lang.String message)
          Prints a message to the debug out stream preceded by a line number (incremented count) and a tab character.
static void printStackTrace()
          Prints a debug stack trace of the current thread to the debug out stream.
static void printStackTrace(java.lang.Throwable ex)
          Prints an exception's stack trace to the debug out stream.
static void removeTraceCategory(java.lang.Object category)
           
static void setLogStream(java.io.PrintStream log)
          Explicitly sets stream for debug messages to be sent to.
static void trace(java.lang.Object category, java.lang.String description)
          Output a trace if the category is enabled and general output is enabled.
static void trace(java.lang.Object category, java.lang.Throwable ex)
          Output a stack trace if the category is enabled and general output is enabled.
static void warn(java.lang.Object category, boolean condition, java.lang.String description)
          Output a warning if the category is enabled, and a condition is true, and general output is enabled.
static void warn(java.lang.Object category, java.lang.String description)
          Outputs a warning if the category is enabled and general output is enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

public static java.io.PrintStream out

count

public static int count

Common counter variable used as 'line numbers' for debug output messages.

Example useage: Debug.out.println(++Debug.count+"\tDebug Message");
or for the same output use: Debug.printlnc("Debug Message");

Constructor Detail

Debug

public Debug()
Method Detail

enableOutput

public static void enableOutput(boolean enable)
Enables or disables all output of debug messages to System.err.

setLogStream

public static void setLogStream(java.io.PrintStream log)
Explicitly sets stream for debug messages to be sent to.

enableAssert

public static void enableAssert(boolean enable)
Enables or disables the checking of conditions in precondition() and check()

assert

public static void assert(boolean condition)
                   throws AssertionException

Asserts a condition. Use this to describe assumed state and parameter values. An AssertionExcpetion is raised if the given condition is not true.

An error here usually indicates a problem with the use of the class.


assert

public static void assert(boolean condition,
                          java.lang.String description)
                   throws AssertionException

Asserts a condition before a method body is run. Use this to describe assumed state and parameter values. A AssertionExcpetion is raised if the given condition is not true.

An error here usually indicates a problem with the use of the class.


addTraceCategory

public static void addTraceCategory(java.lang.Object category)

Category based tracing and warning.

Pass in a unique Class or other object that supports a meaningful toString operation. Then when any call to trace or warning is called, the trace is only displayed if an addTraceCategory() call was made with the same category object.

Typical useage is: addTraceCategory(SomeObject.class);


removeTraceCategory

public static void removeTraceCategory(java.lang.Object category)

trace

public static void trace(java.lang.Object category,
                         java.lang.String description)

Output a trace if the category is enabled and general output is enabled.

Typical useage is: trace(SomeObject.class, "doing something to SomeObject now...");


trace

public static void trace(java.lang.Object category,
                         java.lang.Throwable ex)

Output a stack trace if the category is enabled and general output is enabled.

Typical useage is: trace(SomeObject.class, x);


warn

public static void warn(java.lang.Object category,
                        boolean condition,
                        java.lang.String description)

Output a warning if the category is enabled, and a condition is true, and general output is enabled.

Typical useage: warn(SomeObject.class, someObject1.isBroken(), "someObject1 is broken!");


warn

public static void warn(java.lang.Object category,
                        java.lang.String description)

Outputs a warning if the category is enabled and general output is enabled.

Typical useage: warn(SomeObject.class, "this shouldn't have happened!");


printStackTrace

public static void printStackTrace()
Prints a debug stack trace of the current thread to the debug out stream.

printStackTrace

public static void printStackTrace(java.lang.Throwable ex)
Prints an exception's stack trace to the debug out stream.

println

public static void println(java.lang.String message)
Prints a message (and a cr/lf) to the debug out stream.

print

public static void print(java.lang.String message)
Prints a message to the debug out stream.

printlnc

public static void printlnc(java.lang.String message)

Prints a message to the debug out stream preceded by a line number (incremented count) and a tab character. This is used to track repetetive operations (like painting algorhythms).

Typical useage: printlnc("SomeObject.paint() called");


flush

public static void flush()
Flushes the debug out stream buffer.

debugRect

public static void debugRect(java.awt.Graphics g,
                             int x,
                             int y,
                             int width,
                             int height)

Paints a color-cycled hashmarked rectangle in the passed bounds. Used for debugging paint messages. As subsequent calls are made to debugRect, the hash direction of the debug rectangle will alternate directions, cycle through colors, and vary in hash-mark spacing. This is to allow a viewer to distinguish between different and often repetetive calls to debugRect.

Typical useage: public void paint(Graphics g) { Rectangle clip = g.getClipBounds(); Debug.debugRect(g, clip.x, clip.y, clip.width, clip.height); }