001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.classreader;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: public abstract class Printer extends VisitorBase {
039: private PrintWriter out;
040: private String indentText = " ";
041: private int indentLevel = 0;
042:
043: public Printer(PrintWriter out) {
044: this .out = out;
045: }
046:
047: public String getIndentText() {
048: return indentText;
049: }
050:
051: public void setIndentText(String indentText) {
052: this .indentText = indentText;
053: }
054:
055: protected Printer append(boolean b) {
056: out.print(b);
057: return this ;
058: }
059:
060: protected Printer append(char c) {
061: out.print(c);
062: return this ;
063: }
064:
065: protected Printer append(char[] s) {
066: out.print(s);
067: return this ;
068: }
069:
070: protected Printer append(double d) {
071: out.print(d);
072: return this ;
073: }
074:
075: protected Printer append(float f) {
076: out.print(f);
077: return this ;
078: }
079:
080: protected Printer append(int i) {
081: out.print(i);
082: return this ;
083: }
084:
085: protected Printer append(long l) {
086: out.print(l);
087: return this ;
088: }
089:
090: protected Printer append(Object obj) {
091: out.print(obj);
092: return this ;
093: }
094:
095: protected Printer append(String s) {
096: out.print(s);
097: return this ;
098: }
099:
100: protected Printer indent() {
101: for (int i = 0; i < indentLevel; i++) {
102: append(getIndentText());
103: }
104:
105: return this ;
106: }
107:
108: protected Printer eol() {
109: out.println();
110: return this ;
111: }
112:
113: protected void raiseIndent() {
114: indentLevel++;
115: }
116:
117: protected void lowerIndent() {
118: indentLevel--;
119: }
120: }
|