org.dellroad.jc.cgen
Class CodeWriter

java.lang.Object
  extended byjava.io.Writer
      extended byjava.io.PrintWriter
          extended byorg.dellroad.jc.cgen.CodeWriter

public class CodeWriter
extends PrintWriter

Extension of PrintWriter that contains methods useful for generating and formatting C source files. Basically you can set an indentation level (see indent()) that persists for subsequent lines until you unset it (see undent()).


Field Summary
protected  int indent
           
protected  int indentLevel
           
protected  boolean needIndent
           
protected  Writer w
           
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
CodeWriter(Writer w)
          Constructor.
CodeWriter(Writer w, int indent)
          Constructor.
 
Method Summary
protected  void doIndent()
          Output enough tabs and spaces to achieve current indentation.
 int getIndent()
          Get the current indentation level.
 void indent()
          Increase the current indentation level by one.
 void println()
           
 void setIndent(int level)
          Set indentation level to an absolute number of indents.
 void undent()
          Decrease the current indentation level by one.
 void write(char[] buf)
           
 void write(char[] buf, int off, int len)
           
 void write(int ch)
           
 void write(String s)
           
 void write(String s, int off, int len)
           
 
Methods inherited from class java.io.PrintWriter
checkError, close, flush, print, print, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, println, setError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

w

protected final Writer w

indent

protected final int indent

indentLevel

protected int indentLevel

needIndent

protected boolean needIndent
Constructor Detail

CodeWriter

public CodeWriter(Writer w)
Constructor. Uses the default indentation of 8 spaces.

Parameters:
w - underlying output

CodeWriter

public CodeWriter(Writer w,
                  int indent)
Constructor.

Parameters:
w - underlying output
indent - number of spaces for each indentation level
Method Detail

setIndent

public void setIndent(int level)
Set indentation level to an absolute number of indents.

Parameters:
level - Non-negative indentation level

getIndent

public int getIndent()
Get the current indentation level.


indent

public void indent()
Increase the current indentation level by one.


undent

public void undent()
Decrease the current indentation level by one.


println

public void println()

doIndent

protected void doIndent()
Output enough tabs and spaces to achieve current indentation.


write

public void write(int ch)

write

public void write(char[] buf)

write

public void write(char[] buf,
                  int off,
                  int len)

write

public void write(String s)

write

public void write(String s,
                  int off,
                  int len)