|
1 |
| package edu.rice.cs.dynamicjava.symbol.type; |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| public class TabPrintWriter extends java.io.PrintWriter { |
|
8 |
| private final int _tabSize; |
|
9 |
| private int _numSpaces; |
|
10 |
| |
|
11 |
0
| public TabPrintWriter(java.io.Writer writer, int tabSize) {
|
|
12 |
0
| super(writer);
|
|
13 |
0
| _tabSize = tabSize;
|
|
14 |
0
| _numSpaces = 0;
|
|
15 |
| } |
|
16 |
| |
|
17 |
| |
|
18 |
0
| public void indent() { _numSpaces += _tabSize; }
|
|
19 |
0
| public void unindent() { _numSpaces -= _tabSize; }
|
|
20 |
| |
|
21 |
0
| public void startLine(java.lang.Object s) {
|
|
22 |
0
| startLine();
|
|
23 |
0
| print(s);
|
|
24 |
| } |
|
25 |
| |
|
26 |
0
| public void startLine() {
|
|
27 |
0
| println();
|
|
28 |
0
| for (int i = 0; i < _numSpaces; i++) { print(' '); }
|
|
29 |
| } |
|
30 |
| |
|
31 |
0
| public void printEscaped(java.lang.Object o) { printEscaped(o.toString()); }
|
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
0
| public void printEscaped(java.lang.String s) {
|
|
37 |
0
| for (int i = 0; i < s.length(); i++) {
|
|
38 |
0
| char c = s.charAt(i);
|
|
39 |
0
| switch (c) {
|
|
40 |
0
| case '\b': print("\\b"); break;
|
|
41 |
0
| case '\t': print("\\t"); break;
|
|
42 |
0
| case '\n': print("\\n"); break;
|
|
43 |
0
| case '\f': print("\\f"); break;
|
|
44 |
0
| case '\r': print("\\r"); break;
|
|
45 |
0
| case '\"': print("\\\""); break;
|
|
46 |
0
| case '\'': print("\\\'"); break;
|
|
47 |
0
| case '\\': print("\\\\"); break;
|
|
48 |
0
| default:
|
|
49 |
0
| if (c < ' ' || c == '\u007f') {
|
|
50 |
0
| print('\\');
|
|
51 |
| |
|
52 |
0
| java.lang.String num = java.lang.Integer.toOctalString(c);
|
|
53 |
0
| while (num.length() < 3) num = "0" + num;
|
|
54 |
0
| print(num);
|
|
55 |
| } |
|
56 |
0
| else { print(c); }
|
|
57 |
0
| break;
|
|
58 |
| } |
|
59 |
| } |
|
60 |
| } |
|
61 |
| |
|
62 |
| |
|
63 |
0
| public void printPossiblyEscaped(java.lang.String s, boolean lossless) {
|
|
64 |
0
| if (lossless) {
|
|
65 |
0
| print("\"");
|
|
66 |
0
| printEscaped(s);
|
|
67 |
0
| print("\"");
|
|
68 |
| } else { |
|
69 |
0
| print(s);
|
|
70 |
| } |
|
71 |
| } |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
0
| public void printSerialized(java.lang.Object o) {
|
|
77 |
0
| java.io.ByteArrayOutputStream bs = new java.io.ByteArrayOutputStream();
|
|
78 |
0
| try {
|
|
79 |
0
| java.io.ObjectOutputStream objOut = new java.io.ObjectOutputStream(bs);
|
|
80 |
0
| try { objOut.writeObject(o); }
|
|
81 |
0
| finally { objOut.close(); }
|
|
82 |
| } |
|
83 |
0
| catch (java.io.IOException e) { throw new java.lang.RuntimeException(e); }
|
|
84 |
0
| printBytes(bs.toByteArray());
|
|
85 |
| } |
|
86 |
| |
|
87 |
| |
|
88 |
0
| public void printPossiblySerialized(java.lang.Object o, boolean lossless) {
|
|
89 |
0
| if (lossless) {
|
|
90 |
0
| printSerialized(o);
|
|
91 |
0
| print(" ");
|
|
92 |
0
| printEscaped(o);
|
|
93 |
| } else { |
|
94 |
0
| print(o);
|
|
95 |
| } |
|
96 |
| } |
|
97 |
| |
|
98 |
0
| private void printBytes(byte[] bs) {
|
|
99 |
0
| for (byte b : bs) {
|
|
100 |
0
| int unsigned = ((int)b) & 0xff;
|
|
101 |
0
| java.lang.String num = java.lang.Integer.toHexString(unsigned);
|
|
102 |
0
| if (num.length() == 1) print("0");
|
|
103 |
0
| print(num);
|
|
104 |
| } |
|
105 |
| } |
|
106 |
| |
|
107 |
0
| public void startObject(String name) {
|
|
108 |
0
| print(name);
|
|
109 |
0
| indent();
|
|
110 |
| } |
|
111 |
| } |