Java™ Pretty Printer Library v0.5


de.uka.ilkd.pp
Class StringBackend

java.lang.Object
  extended by de.uka.ilkd.pp.StringBackend
All Implemented Interfaces:
Backend<NoExceptions>

public class StringBackend
extends java.lang.Object
implements Backend<NoExceptions>

A Backend which appends all output to a StringBuilder or StringBuffer. The mark(Object o) method does nothing in this implementation. There is a method count() which returns the number of characters written by this so far. The method getString() gets the output written so far.


Field Summary
protected  int initOutLength
          The initial number of characters in out, used by the implementation of count().
protected  int lineWidth
          The maximum width of lines to be written to this backend.
protected  java.lang.Appendable out
          The StringBuffer or StringBuilder output will be accumulated in.
 
Constructor Summary
StringBackend(int lineWidth)
          Create a new StringBackend.
StringBackend(java.lang.StringBuffer sb, int lineWidth)
          Deprecated. consider using the constructor StringBackend(StringBuilder, int), as StringBuilders are faster, and multi-threaded access to sb is probably not going to work anyhow.
StringBackend(java.lang.StringBuilder sb, int lineWidth)
          Create a new StringBackend.
 
Method Summary
 void close()
          Closes this backend
 int count()
          Returns the number of characters written through this backend.
 void flush()
          Flushes any buffered output
 java.lang.String getString()
          Returns the accumulated output
 int lineWidth()
          Returns the available space per line
 void mark(java.lang.Object o)
          Gets called to record a mark() call in the input.
 int measure(java.lang.String s)
          Returns the space required to print the String s
 void newLine()
          Start a new line.
 void print(java.lang.String s)
          Append a String s to the output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.lang.Appendable out
The StringBuffer or StringBuilder output will be accumulated in. Some of the implementations rely on this being either a StringBuilder or StringBuffer, and all implementations in this class guarantee it. If you subclass StringBackend, beware!


lineWidth

protected int lineWidth
The maximum width of lines to be written to this backend.


initOutLength

protected int initOutLength
The initial number of characters in out, used by the implementation of count().

Constructor Detail

StringBackend

public StringBackend(java.lang.StringBuilder sb,
                     int lineWidth)
Create a new StringBackend. This will append all output to the given StringBuilder sb.


StringBackend

public StringBackend(java.lang.StringBuffer sb,
                     int lineWidth)
Deprecated. consider using the constructor StringBackend(StringBuilder, int), as StringBuilders are faster, and multi-threaded access to sb is probably not going to work anyhow.

Create a new StringBackend. This will append all output to the given StringBuffer sb.


StringBackend

public StringBackend(int lineWidth)
Create a new StringBackend. This will accumulate output in a fresh, private StringBuilder.

Method Detail

print

public void print(java.lang.String s)
Append a String s to the output. s contains no newlines.

Specified by:
print in interface Backend<NoExceptions>

newLine

public void newLine()
Start a new line.

Specified by:
newLine in interface Backend<NoExceptions>

close

public void close()
Closes this backend

Specified by:
close in interface Backend<NoExceptions>

flush

public void flush()
Flushes any buffered output

Specified by:
flush in interface Backend<NoExceptions>

mark

public void mark(java.lang.Object o)
Gets called to record a mark() call in the input.

Specified by:
mark in interface Backend<NoExceptions>

count

public int count()
Returns the number of characters written through this backend.


lineWidth

public int lineWidth()
Returns the available space per line

Specified by:
lineWidth in interface Backend<NoExceptions>

measure

public int measure(java.lang.String s)
Returns the space required to print the String s

Specified by:
measure in interface Backend<NoExceptions>

getString

public java.lang.String getString()
Returns the accumulated output


SourceForge.net