Clover coverage report - DynamicJava Test Coverage (dynamicjava-20130622-r5436)
Coverage timestamp: Sat Jun 22 2013 03:01:29 CDT
file stats: LOC: 111   Methods: 12
NCLOC: 84   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TabPrintWriter.java 0% 0% 0% 0%
coverage
 1    package edu.rice.cs.dynamicjava.symbol.type;
 2   
 3   
 4    /**
 5    * An extension of PrintWriter to support indenting levels.
 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    /** ups indent for any future new lines. */
 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    /** Print a string in Java source-compatible escaped form. All control characters
 34    * (including line breaks) and quoting punctuation are escaped with a backslash.
 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    // must use 3 digits so that unescaping doesn't consume too many chars ("\12" vs. "\0012")
 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    /** Conditionally print the serialzed form of the given object. */
 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    /** Print the serialized form of the given object as a hexadecimal number.
 74    * @throws RuntimeException If the object is not serializable.
 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    /** Conditionally print the serialzed form of the given object. */
 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    }