Class JSourceWriter
java.lang.Object
java.io.Writer
org.codehaus.modello.plugin.java.javasource.JSourceWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
The writer used by the modello classes
- Version:
- $Revision$ $Date$
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Flag for indicating whether we need to add the whitespace to beginning of next write callprivate boolean
A flag indicating whether this JSourceWriter should perform autoflush at the end of a new linestatic final char
The default character to use for indentationstatic final short
The default indentation sizeprivate String
The line separator to use for the writeln methodsprivate Writer
The writer to send all output toprivate char[]
The tab representationprivate char
The character to use for indentationprivate short
The current tab levelprivate short
The tab (indentation) size -
Constructor Summary
ConstructorsConstructorDescriptionJSourceWriter
(Writer out) Creates a new JSourceWriterJSourceWriter
(Writer out, boolean autoflush) Creates a new JSourceWriterJSourceWriter
(Writer out, short tabSize, boolean autoflush) Creates a new JSourceWriterJSourceWriter
(Writer out, short tabSize, char tabChar, boolean autoflush) Creates a new JSourceWriter -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
private void
Creates the tab from the tabSize and the tabCharprivate void
void
flush()
protected char
protected short
protected short
Returns the current indent size (getIndentLevel()*tabSize);Returns the line separator being used by this JSourceWritervoid
indent()
Increases the indentation level by 1boolean
Checks to see if the cursor is positioned on a new lineprivate void
linefeed()
writes the line separator character to the writervoid
setLineSeparator
(String lineSeparator) Sets the line separator to use at the end of each linevoid
unindent()
Decreases the indentation level by 1void
write
(boolean b) void
write
(char[] buf) void
write
(char[] buf, int off, int len) void
write
(double d) void
write
(float f) void
write
(int c) void
write
(long l) void
void
void
protected void
void
writeln()
void
writeln
(boolean b) void
writeln
(char c) void
writeln
(char[] chars) void
writeln
(double d) void
writeln
(float f) void
writeln
(int i) void
writeln
(long l) void
void
-
Field Details
-
DEFAULT_CHAR
public static final char DEFAULT_CHARThe default character to use for indentation- See Also:
-
DEFAULT_SIZE
public static final short DEFAULT_SIZEThe default indentation size- See Also:
-
lineSeparator
The line separator to use for the writeln methods -
addIndentation
private boolean addIndentationFlag for indicating whether we need to add the whitespace to beginning of next write call -
autoflush
private boolean autoflushA flag indicating whether this JSourceWriter should perform autoflush at the end of a new line -
tabSize
private short tabSizeThe tab (indentation) size -
tab
private char[] tabThe tab representation -
tabChar
private char tabCharThe character to use for indentation -
tabLevel
private short tabLevelThe current tab level -
out
The writer to send all output to
-
-
Constructor Details
-
JSourceWriter
Creates a new JSourceWriter- Parameters:
out
- the Writer to write the actual output to
-
JSourceWriter
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
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
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 Details
-
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
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
-
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
-
writeln
-
writeln
public void writeln(char[] chars) -
writeln
public void writeln(boolean b) -
writeln
public void writeln(char c) -
close
public void close() -
flush
public void flush() -
write
-
write
-
write
public void write(char[] buf) -
write
public void write(int c) -
write
public void write(char[] buf, int off, int len) -
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
-