KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sli > kim > classfile > Debug


1 package sli.kim.classfile;
2
3 import java.io.PrintStream JavaDoc;
4
5 /**
6 * All classfile debugging information gets piped through this class.
7 * You can turn off categories of debug information by setting the
8 * appropriate String to null.
9 */

10 public class Debug {
11     public static String JavaDoc readClass = "read class: ";
12     public static String JavaDoc readConstPool = "read CP: ";
13     public static String JavaDoc readField = "read field: ";
14     public static String JavaDoc readMethod = "read method: ";
15     public static String JavaDoc readCode = "read code: ";
16     public static String JavaDoc readInterface = "read interface: ";
17     public static String JavaDoc readLineNumbers = "read line numbers: ";
18     public static String JavaDoc readLocalVariables = "read local variables: ";
19     public static String JavaDoc readInnerClasses = "read inner classes: ";
20     public static String JavaDoc readUnknownAttribute = "read unknown attribute: ";
21     public static String JavaDoc readBadData = "read bad data: ";
22
23     public static String JavaDoc writeClass = "write class: ";
24     public static String JavaDoc writeConstPool = "write CP: ";
25     public static String JavaDoc writeField = "write field: ";
26     public static String JavaDoc writeMethod = "write method: ";
27     public static String JavaDoc writeCode = "write code: ";
28     public static String JavaDoc writeInterface = "write interface: ";
29     public static String JavaDoc writeLineNumbers = "write line numbers: ";
30     public static String JavaDoc writeLocalVariables = "write local variables: ";
31     public static String JavaDoc writeInnerClasses = "write inner classes: ";
32     public static String JavaDoc writeUnknownAttribute = "write unknown attribute: ";
33
34     /**
35     * Indent subsequent messages. Subsequent messages will be indented by
36     * two spaces until outdent() is called. All calls to indent() should eventually
37     * be followed by a call to outdent().
38     */

39     public static void indent() {
40         indentLevel++;
41     }
42     /**
43     * Outdent subsequent messages. This should only be called after a previous
44     * call to indent().
45     */

46     public static void outdent() {
47         indentLevel--;
48     }
49
50     /**
51     * Enable or disable printing of any debug message.
52     */

53     public static void setEnabled(boolean e) {
54         enabled = e;
55     }
56     /**
57     * Get whether printing of debug messages is enabled.
58     */

59     public static boolean isEnabled() {
60         return enabled;
61     }
62
63     /**
64     * Redirect where debug messages are sent.
65     */

66     public static void setOutput(PrintStream JavaDoc out) {
67         msgs = out;
68     }
69     /**
70     * Get the destination of debug messages.
71     */

72     public static PrintStream JavaDoc getOutput() {
73         return msgs;
74     }
75
76     /**
77     * Print a debug message. If the prefix is null, the message is not printed.
78     * The message will be prefixed by blank space, the length of which is
79     * determined by the current level of indentation.
80     */

81     public static void println(String JavaDoc prefix, String JavaDoc msg) {
82         if (enabled && prefix != null) {
83             for (int i = 0; i < indentLevel; i++)
84                 msgs.print(" ");
85             msgs.println(prefix + msg);
86         }
87     }
88
89     private static PrintStream JavaDoc msgs = System.out;
90     private static boolean enabled = true;
91     private static int indentLevel = 0;
92 }
Popular Tags