Class JSourceWriter
- java.lang.Object
-
- java.io.Writer
-
- org.codehaus.modello.plugin.java.javasource.JSourceWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public class JSourceWriter extends java.io.WriterThe writer used by the modello classes- Version:
- $Revision$ $Date$
-
-
Field Summary
Fields Modifier and Type Field Description private booleanaddIndentationFlag for indicating whether we need to add the whitespace to beginning of next write callprivate booleanautoflushA flag indicating whether this JSourceWriter should perform autoflush at the end of a new linestatic charDEFAULT_CHARThe default character to use for indentationstatic shortDEFAULT_SIZEThe default indentation sizeprivate java.lang.StringlineSeparatorThe line separator to use for the writeln methodsprivate java.io.WriteroutThe writer to send all output toprivate char[]tabThe tab representationprivate chartabCharThe character to use for indentationprivate shorttabLevelThe current tab levelprivate shorttabSizeThe tab (indentation) size
-
Constructor Summary
Constructors Constructor Description JSourceWriter(java.io.Writer out)Creates a new JSourceWriterJSourceWriter(java.io.Writer out, boolean autoflush)Creates a new JSourceWriterJSourceWriter(java.io.Writer out, short tabSize, boolean autoflush)Creates a new JSourceWriterJSourceWriter(java.io.Writer out, short tabSize, char tabChar, boolean autoflush)Creates a new JSourceWriter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()private voidcreateTab()Creates the tab from the tabSize and the tabCharprivate voidensureIndent()voidflush()protected chargetIndentChar()protected shortgetIndentLevel()protected shortgetIndentSize()Returns the current indent size (getIndentLevel()*tabSize);java.lang.StringgetLineSeparator()Returns the line separator being used by this JSourceWritervoidindent()Increases the indentation level by 1booleanisNewline()Checks to see if the cursor is positioned on a new lineprivate voidlinefeed()writes the line separator character to the writervoidsetLineSeparator(java.lang.String lineSeparator)Sets the line separator to use at the end of each linevoidunindent()Decreases the indentation level by 1voidwrite(boolean b)voidwrite(char[] buf)voidwrite(char[] buf, int off, int len)voidwrite(double d)voidwrite(float f)voidwrite(int c)voidwrite(long l)voidwrite(java.lang.Object obj)voidwrite(java.lang.String s)voidwrite(java.lang.String s, int off, int len)protected voidwriteIndent()voidwriteln()voidwriteln(boolean b)voidwriteln(char c)voidwriteln(char[] chars)voidwriteln(double d)voidwriteln(float f)voidwriteln(int i)voidwriteln(long l)voidwriteln(java.lang.Object obj)voidwriteln(java.lang.String string)
-
-
-
Field Detail
-
DEFAULT_CHAR
public static final char DEFAULT_CHAR
The default character to use for indentation- See Also:
- Constant Field Values
-
DEFAULT_SIZE
public static final short DEFAULT_SIZE
The default indentation size- See Also:
- Constant Field Values
-
lineSeparator
private java.lang.String lineSeparator
The line separator to use for the writeln methods
-
addIndentation
private boolean addIndentation
Flag for indicating whether we need to add the whitespace to beginning of next write call
-
autoflush
private boolean autoflush
A flag indicating whether this JSourceWriter should perform autoflush at the end of a new line
-
tabSize
private short tabSize
The tab (indentation) size
-
tab
private char[] tab
The tab representation
-
tabChar
private char tabChar
The character to use for indentation
-
tabLevel
private short tabLevel
The current tab level
-
out
private java.io.Writer out
The writer to send all output to
-
-
Constructor Detail
-
JSourceWriter
public JSourceWriter(java.io.Writer out)
Creates a new JSourceWriter- Parameters:
out- the Writer to write the actual output to
-
JSourceWriter
public JSourceWriter(java.io.Writer out, boolean autoflush)Creates a new JSourceWriter- Parameters:
out- the Writer to write the actual output toautoflush- a boolean indicating whether or not to perform automatic flush at the end of a line
-
JSourceWriter
public JSourceWriter(java.io.Writer out, short tabSize, boolean autoflush)Creates a new JSourceWriter- Parameters:
out- the Writer to write the actual output totabSize- the size of each indentationautoflush- a boolean indicating whether or not to perform automatic flush at the end of a line
-
JSourceWriter
public JSourceWriter(java.io.Writer out, short tabSize, char tabChar, boolean autoflush)Creates a new JSourceWriter- Parameters:
out- the Writer to write the actual output totabSize- the size of each indentationtabChar- the character to use for indentationautoflush- a boolean indicating whether or not to perform automatic flush at the end of a line
-
-
Method Detail
-
getLineSeparator
public java.lang.String getLineSeparator()
Returns the line separator being used by this JSourceWriter- Returns:
- the line separator being used by this JSourceWriter
-
indent
public void indent()
Increases the indentation level by 1
-
isNewline
public boolean isNewline()
Checks to see if the cursor is positioned on a new line- Returns:
- true if the cursor is at the start of a new line, otherwise false
-
setLineSeparator
public void setLineSeparator(java.lang.String lineSeparator)
Sets the line separator to use at the end of each line- Parameters:
lineSeparator- the String to use as a line separator.
Typically a line separator will be one of the following:
"\r\n" for MS Windows
"\n" for UNIX
"\r" for Macintosh
-
unindent
public void unindent()
Decreases the indentation level by 1
-
write
public void write(float f)
-
write
public void write(long l)
-
write
public void write(double d)
-
write
public void write(java.lang.Object obj)
-
write
public void write(boolean b)
-
writeln
public void writeln()
-
writeln
public void writeln(float f)
-
writeln
public void writeln(long l)
-
writeln
public void writeln(int i)
-
writeln
public void writeln(double d)
-
writeln
public void writeln(java.lang.Object obj)
-
writeln
public void writeln(java.lang.String string)
-
writeln
public void writeln(char[] chars)
-
writeln
public void writeln(boolean b)
-
writeln
public void writeln(char c)
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer
-
flush
public void flush()
- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer
-
write
public void write(java.lang.String s, int off, int len)- Overrides:
writein classjava.io.Writer
-
write
public void write(java.lang.String s)
- Overrides:
writein classjava.io.Writer
-
write
public void write(char[] buf)
- Overrides:
writein classjava.io.Writer
-
write
public void write(int c)
- Overrides:
writein classjava.io.Writer
-
write
public void write(char[] buf, int off, int len)- Specified by:
writein classjava.io.Writer
-
getIndentLevel
protected short getIndentLevel()
-
getIndentSize
protected short getIndentSize()
Returns the current indent size (getIndentLevel()*tabSize);- Returns:
- the current indent size
-
getIndentChar
protected char getIndentChar()
-
writeIndent
protected void writeIndent()
-
ensureIndent
private void ensureIndent()
-
linefeed
private void linefeed()
writes the line separator character to the writer
-
createTab
private void createTab()
Creates the tab from the tabSize and the tabChar
-
-