UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.debugging
Class Debug

java.lang.Object
  |
  +--edu.berkeley.guir.lib.debugging.Debug

public class Debug
extends Object

Lots of debugging utilities, including log file output, stream output, graphical window output, and object introspection.

Have an instance in each class you want and use that instance. For example: private static final Debug debug = new Debug(Debug.ON);

Turn on debugging at runtime by setting the appropriate system environment variables. If no debugging output environment variables are set, debugging is off.

Here is an example of the introspection debugging:

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.0-1.0.0, Aug 25 1997, JH
               Created class
             - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib release
 

Since:
1.3RC1
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu )

Field Summary
static boolean COMPILE_ASSERT
          Set the guir.debug.assert system property to initialize this field.
static boolean ENABLE_DEBUG
          If one of guir.debug.output, guir.debug.window, or guir.debug.logerr is not set true, then this is false and turns off debugging output.
static boolean LOGERR
          Set the guir.debug.logerr system property to initialize this field.
static boolean OFF
          Constant for debug constructor to turn debugging off for this class.
static boolean ON
          Constant for debug constructor to turn debugging on for this class.
static boolean OUTPUT
          Set the guir.debug.output system property to initialize this field.
static boolean WINDOW
          Set the guir.debug.window system property to initialize this field.
 
Constructor Summary
Debug()
          Create a new debugging object.
Debug(boolean newMode)
          Create a new debugging object.
 
Method Summary
 void assert(boolean predicate, String strErrorMessage)
          Validate a predicate.
static void displayObjectStream(Object obj)
          Use introspection to debug an object, using the specified output i/o.
static void displayObjectStream(Object obj, OutputStream out)
          Use introspection to debug an object, using the specified output i/o.
static void displayObjectStream(Object obj, PrintWriter out)
          Use introspection to debug an object, using the specified output i/o.
static void displayObjectTree(Object obj)
          Use introspection to debug an object, using a JTree as output.
static String[] getCallingClassAndMethod()
          Get the name of the method that called you (the one that called the method that is calling this debug method).
static String[] getCurrentClassAndMethod()
          Get the name of the current method (the one that is calling this debug method).
 boolean getDebugMode()
           
 DebugWindow getDebugWindow()
           
static void main(String[] argv)
           
 void println()
          Print out a blank line with no headers.
 void println(boolean flag)
           
 void println(byte b)
           
 void println(byte[] bArray)
           
 void println(char ch)
           
 void println(char[] chArray)
           
 void println(double d)
           
 void println(double[] dArray)
           
 void println(float f)
           
 void println(float[] fArray)
           
 void println(int i)
           
 void println(int[] intArray)
           
 void println(Object obj)
          Print out an error message.
 void println(Object[] objArray)
           
 void println(Polygon poly)
          This is because polygon is stoopid.
 void println(short s)
           
 void println(short[] sArray)
           
 void println(String str)
           
 void println(Throwable e)
           
 void printStackTrace()
          Print the stack trace right now.
 void setDebug(boolean flag)
          Turn debugging on or off.
static void setUseShortClassNames(boolean flag)
          Short class name is String.
static void setUseWindow(boolean flag)
          Create a new debug window and do output there.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPILE_ASSERT

public static final boolean COMPILE_ASSERT
Set the guir.debug.assert system property to initialize this field. Set to true to enable assert statements. Default if property not defined is false. Example:
java -Dguir.debug.assert=true ...

LOGERR

public static boolean LOGERR
Set the guir.debug.logerr system property to initialize this field. Record debugging messages to the debugging logfile or not? Set to true if you want a logfile. Default if property not defined is false. Example:
java -Dguir.debug.logerr=true ...

WINDOW

public static boolean WINDOW
Set the guir.debug.window system property to initialize this field. Send debugging messages to the TextArea Window or not? Set to true if you want a debugging window. Default if property not defined is false. Example:
java -Dguir.debug.window=true ...

OUTPUT

public static boolean OUTPUT
Set the guir.debug.output system property to initialize this field. Print debugging messages to the normal output or not? Set to true if you want output. Default if property not defined is false. Example:
java -Dguir.debug.output=true ...
This will normally send output to stdout. The output stream can be redirected with method setOutput().

ENABLE_DEBUG

public static boolean ENABLE_DEBUG
If one of guir.debug.output, guir.debug.window, or guir.debug.logerr is not set true, then this is false and turns off debugging output.

ON

public static final boolean ON
Constant for debug constructor to turn debugging on for this class.

OFF

public static final boolean OFF
Constant for debug constructor to turn debugging off for this class.
Constructor Detail

Debug

public Debug()
Create a new debugging object.

Debug

public Debug(boolean newMode)
Create a new debugging object.
Parameters:
newMode - is true if debugging is on, false otherwise.
Method Detail

setUseShortClassNames

public static void setUseShortClassNames(boolean flag)
Short class name is String. Long class name is java.lang.String.
Parameters:
flag - is true if short class names are to be used, false if full package names are to be used.

setUseWindow

public static void setUseWindow(boolean flag)
Create a new debug window and do output there.

setDebug

public void setDebug(boolean flag)
Turn debugging on or off.

getDebugWindow

public DebugWindow getDebugWindow()

getDebugMode

public boolean getDebugMode()

assert

public final void assert(boolean predicate,
                         String strErrorMessage)
Validate a predicate. If predicate evaluates to true, then the method call passes through with no side effects. If the predicate is false, then stack will be printed out, and the program will exit immediately.
 Sample: 
         // This is okay.
         Assert.ASSERT(iValue > 0, "Message");

         // This is also okay.
         Assert.ASSERT(cValue == 'a' || cValue == 'A', "Message");

         // This is WRONG.
         Assert.ASSERT(iValue++, "Message");
 
Parameters:
predicate - is an expression that evaluates to a boolean to test. You should not pass in an expression with side any effects.
strErrorMessage - is the error message to print out if the assertion should fail.
Throws:
AssertionFailedException - if predicate is false. AssertionFailedException is a subclass of IllegalArgumentException, which is a RuntimeException.

printStackTrace

public void printStackTrace()
Print the stack trace right now.

getCurrentClassAndMethod

public static final String[] getCurrentClassAndMethod()
Get the name of the current method (the one that is calling this debug method).
Returns:
String[0] is class name, String[1] is method name.

getCallingClassAndMethod

public static final String[] getCallingClassAndMethod()
Get the name of the method that called you (the one that called the method that is calling this debug method).
Returns:
String[0] is class name, String[1] is method name.

displayObjectTree

public static void displayObjectTree(Object obj)
Use introspection to debug an object, using a JTree as output. Requires privileged access to reflection to work fully.

displayObjectStream

public static void displayObjectStream(Object obj,
                                       OutputStream out)
Use introspection to debug an object, using the specified output i/o. Requires privileged access to reflection to work fully.

displayObjectStream

public static void displayObjectStream(Object obj,
                                       PrintWriter out)
Use introspection to debug an object, using the specified output i/o. Requires privileged access to reflection to work fully.

displayObjectStream

public static void displayObjectStream(Object obj)
Use introspection to debug an object, using the specified output i/o. Requires privileged access to reflection to work fully.

println

public final void println()
Print out a blank line with no headers.

println

public void println(String str)

println

public final void println(Throwable e)

println

public final void println(Object obj)
Print out an error message.
Parameters:
obj - is the Object to print out.

println

public final void println(Object[] objArray)

println

public final void println(boolean flag)

println

public final void println(byte b)

println

public final void println(byte[] bArray)

println

public final void println(short s)

println

public final void println(short[] sArray)

println

public final void println(char ch)

println

public final void println(char[] chArray)

println

public final void println(double d)

println

public final void println(double[] dArray)

println

public final void println(float f)

println

public final void println(float[] fArray)

println

public final void println(int i)

println

public final void println(int[] intArray)

println

public final void println(Polygon poly)
This is because polygon is stoopid.

Makes me wonder if there is some programming language model that lets you dynamically, safely, and securely attach methods to predefined classes, since developers can't always know beforehand what's needed.


main

public static void main(String[] argv)

Copyright Information