|
Arch4J 1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.arch4j.generator.CodeBuffer
This class is used to cleanly format code into a StringBuffer.
A typical use would be to format the contents of a method and then
extract it as a String via the toString()
method.
The code buffer maintains a current indentation level, so that repeated calls to append lines automatically get indented to the proper level. References to a tab character in this class may really represent a number of spaces instead.
Opening braces for a code block will either appear at the end of the current line or on a line by itself. This attribute can be modified after the code buffer has been created.
Field Summary |
Fields inherited from interface org.arch4j.generator.GeneratorConstants |
END_JAVADOC, FILE_DELIMITER, INDENT, LINE_DELIMITERS, MIDDLE_JAVADOC, NEWLINE, SINGLE_COMMENT, SPACE, START_JAVADOC |
Constructor Summary | |
CodeBuffer()
Creates a new CodeBuffer instance. |
|
CodeBuffer(int initialIndentLevel)
Creates a new CodeBuffer instance
with the given indentation level. |
Method Summary | |
void |
append(Object obj)
Append obj to the buffer. |
void |
append(String text)
Append text to the buffer. |
void |
appendAndStartBlock(Object obj)
Append obj to the buffer and start a block. |
void |
appendAndStartBlock(String text)
Append text to the buffer. |
void |
appendBlankLine()
Append the representation of a newline directly to the buffer. |
void |
appendBlankLines(int count)
Append count newlines directly to the buffer. |
void |
appendLine(Object obj)
Append obj to the buffer. |
void |
appendLine(Object obj,
boolean includeNewline)
Append obj to the buffer. |
void |
appendLine(String text)
Append text to the buffer. |
void |
appendLine(String text,
boolean includeNewline)
Append text to the buffer. |
void |
appendLines(String multiLineText)
Append the lines contained in multiLineText one at a time
to the receiver. |
void |
appendMultiLineComment(String multiLineText)
Append the lines contained in multiLineText one at a time
to the receiver within a multi-line comment block. |
void |
appendMultiLineCommentLines(String multiLineText)
Append the lines contained in multiLineText one at a time
to the receiver within an already started multi-line comment block. |
void |
appendSingleLineComment(String commentText)
Append the line contained in commentText
to the receiver within a single-line comment block. |
void |
appendSingleLineCommentLines(String multiLineText)
Append the lines contained in multiLineText one at a time
to the receiver, each preceded by the single-line comment string. |
void |
appendSpace()
Append the representation of a space directly to the buffer. |
void |
appendSpaces(int count)
Append count spaces directly to the buffer. |
void |
appendTab()
Append the representation of a tab directly to the buffer. |
void |
appendTabs()
Append an appropriate number of tabs for the current indent level directly to the buffer. |
void |
appendTabs(int count)
Append count tabs directly to the buffer. |
void |
braceOnSameLine()
Opening braces will now appear at the end of the current line when a new block is started. |
void |
endBlock()
End a code block. |
void |
endMultiLineComment()
End a multi-line comment block. |
void |
newlineBeforeBrace()
Opening braces will now appear on a line by themselves when a new block is started. |
void |
startBlock()
Start a code block. |
void |
startBlock(Object obj)
Start a code block. |
void |
startBlock(String text)
Start a code block. |
void |
startMultiLineComment()
Start a multi-line comment block. |
void |
tabIn()
Increment the current indentation level. |
void |
tabIn(int count)
Increment the current indentation level by count levels. |
void |
tabInAndAppendLine(Object obj)
Increment the current indentation level and then append obj . |
void |
tabInAndAppendLine(Object obj,
boolean includeNewline)
Increment the current indentation level and then append obj . |
void |
tabInAndAppendLine(String text)
Increment the current indentation level and then append text . |
void |
tabInAndAppendLine(String text,
boolean includeNewline)
Increment the current indentation level and then append text . |
void |
tabOut()
Decrement the current indentation level. |
void |
tabOut(int count)
Decrement the current indentation level by count levels. |
void |
tabOutAndAppendLine(Object obj)
Decrement the current indentation level and then append obj . |
void |
tabOutAndAppendLine(Object obj,
boolean includeNewline)
Decrement the current indentation level and then append obj . |
void |
tabOutAndAppendLine(String text)
Decrement the current indentation level and then append text . |
void |
tabOutAndAppendLine(String text,
boolean includeNewline)
Decrement the current indentation level and then append text . |
String |
toString()
Converts the data in this code buffer to a String . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public CodeBuffer()
CodeBuffer
instance.
public CodeBuffer(int initialIndentLevel)
CodeBuffer
instance
with the given indentation level.
initialIndentLevel
- The initial indentation level.Method Detail |
public void newlineBeforeBrace()
public void braceOnSameLine()
public String toString()
String
.
toString
in class Object
public void tabIn()
public void tabIn(int count)
count
levels.
public void tabOut()
public void tabOut(int count)
count
levels.
public void append(Object obj)
obj
to the buffer. The object is converted to a
string (via it's toString()
method and then appended.
obj
- The object to append to the buffer.append(java.lang.String)
public void append(String text)
text
to the buffer. The text is not indented
at the current indentation level; the text is passed through as is.
text
- The text to append to the buffer.public void appendLine(Object obj)
obj
to the buffer. The object is converted to a
string (via it's toString()
method and then appended.
obj
- The object to append to the buffer.appendLine(java.lang.String)
public void appendLine(String text)
text
to the buffer.
The text is indented at the current indentation level.
A newline is also appended.
text
- The text to append to the buffer.appendLine(java.lang.String, boolean)
public void appendLine(Object obj, boolean includeNewline)
obj
to the buffer. The object is converted to a
string (via it's toString()
method and then appended.
A newline is appended if includeNewline
is true.
obj
- The object to append to the buffer.includeNewline
- If true, a newline is also appended.appendLine(java.lang.String, boolean)
public void appendLine(String text, boolean includeNewline)
text
to the buffer.
The text is indented at the current indentation level.
A newline is appended if includeNewline
is true.
text
- The text to append to the buffer.includeNewline
- If true, a newline is also appended.public void appendLines(String multiLineText)
multiLineText
one at a time
to the receiver. This allows a block of code formatted with another
CodeBuffer
to be added using the receiver's indentation
level, but still preserving the other buffer's indentation levels.
multiLineText
- A String containing multiple lines of text.public void tabInAndAppendLine(Object obj)
obj
.
obj
- The object to append to the buffer.tabInAndAppendLine(java.lang.String)
public void tabInAndAppendLine(String text)
text
.
text
- The text to append to the buffer.tabIn()
,
appendLine(java.lang.String)
public void tabInAndAppendLine(Object obj, boolean includeNewline)
obj
.
obj
- The object to append to the buffer.includeNewline
- If true, a newline is also appended.tabInAndAppendLine(java.lang.String, boolean)
public void tabInAndAppendLine(String text, boolean includeNewline)
text
.
text
- The text to append to the buffer.includeNewline
- If true, a newline is also appended.tabIn()
,
appendLine(java.lang.String, boolean)
public void tabOutAndAppendLine(Object obj)
obj
.
obj
- The object to append to the buffer.tabOutAndAppendLine(java.lang.String)
public void tabOutAndAppendLine(String text)
text
.
text
- The text to append to the buffer.tabOut()
,
appendLine(java.lang.String)
public void tabOutAndAppendLine(Object obj, boolean includeNewline)
obj
.
obj
- The object to append to the buffer.includeNewline
- If true, a newline is also appended.tabOutAndAppendLine(java.lang.String, boolean)
public void tabOutAndAppendLine(String text, boolean includeNewline)
text
.
text
- The text to append to the buffer.includeNewline
- If true, a newline is also appended.tabOut()
,
appendLine(java.lang.String, boolean)
public void appendTab()
public void appendTabs()
public void appendTabs(int count)
count
tabs directly to the buffer.
Note: The literal tab character may be represented by a number of spaces.
count
- The number of tabs to append.public void appendBlankLine()
public void appendBlankLines(int count)
count
newlines directly to the buffer.
count
- The number of newlines to append.public void appendSpace()
public void appendSpaces(int count)
count
spaces directly to the buffer.
count
- The number of spaces to append.public void startBlock(Object obj)
obj
- The object to append before the opening brace.startBlock(java.lang.String)
public void startBlock(String text)
text
will appear before the
opening brace. The brace is added automatically, and uses the
current setting for whether the brace is on it's own line or not.
Starting a block increments the indentation level.
For example, an if statement can be coded as:
buffer.startBlock("if (aBoolean)"); buffer.appendLine("doSomething();"); buffer.endBlock();
text
- The text to append before the opening brace.public void appendAndStartBlock(Object obj)
obj
to the buffer and start a block.
obj
- The object to append before the opening brace.appendAndStartBlock(java.lang.String)
public void appendAndStartBlock(String text)
text
to the buffer. The text is not indented
at the current indentation level; the text is passed through as is,
completing a previously started line. Then start a code block.
text
- The text to append to the buffer.startBlock(java.lang.String)
public void startBlock()
public void endBlock()
public void startMultiLineComment()
appendMultiLineCommentLines(java.lang.String)
public void appendMultiLineComment(String multiLineText)
multiLineText
one at a time
to the receiver within a multi-line comment block. This method appends
a complete comment block to the code buffer. If the text only contains
a single line, a space-saving comment block is generated on a single line.
multiLineText
- A String containing multiple lines of comment text.startMultiLineComment()
,
appendMultiLineCommentLines(java.lang.String)
,
endMultiLineComment()
public void appendMultiLineCommentLines(String multiLineText)
multiLineText
one at a time
to the receiver within an already started multi-line comment block.
multiLineText
- A String containing multiple lines of comment text.startMultiLineComment()
,
endMultiLineComment()
public void endMultiLineComment()
public void appendSingleLineComment(String commentText)
commentText
to the receiver within a single-line comment block.
commentText
- A String to append as a single-line comment.public void appendSingleLineCommentLines(String multiLineText)
multiLineText
one at a time
to the receiver, each preceded by the single-line comment string.
multiLineText
- A String containing multiple lines of comment text.
|
Arch4J 1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |