Class SourcePrinter
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an indent to the top of the stack that is a copy of the current top indent.Return the current cursor position (line, column) in the source printer buffer.Deprecated.use toString()indent()
Add the default indentation to the current indentation and push it on the indentation stack.indentWithAlignTo(int column)
Add to the current indentation until it is reaches "column" and push it on the indentation stack.normalizeEolInTextBlock(String content)
Changes all EOL characters in "content" to the EOL character this SourcePrinter is using.Append the source string passed as argument to the buffer.println()
Append a newline to the buffer.Append the source string passed as argument to the buffer, then append a newline.void
Set the top-most indent to the column the cursor was before the lastreindentWithAlignToCursor()
call.void
Set the top-most indent to the column the cursor is currently in, can be undone withreindentToPreviousLevel()
.toString()
unindent()
Pop the last indentation of the indentation stack.
-
Method Details
-
indent
Add the default indentation to the current indentation and push it on the indentation stack. Does not actually output anything. -
indentWithAlignTo
Add to the current indentation until it is reaches "column" and push it on the indentation stack. Does not actually output anything. -
unindent
Pop the last indentation of the indentation stack. Does not actually output anything. -
print
Append the source string passed as argument to the buffer. If this is being appended at the beginning of a line, performs indentation first.The source line to be printed should not contain newline/carriage-return characters; use
println(String)
to automatically append a newline at the end of the source string. If the source line passed as argument contains newline/carriage-return characters would impredictably affect a correct computation of the currentgetCursor()
position.- Parameters:
arg
- source line to be printed (should not contain newline/carriage-return characters)- Returns:
- this instance, for nesting calls to method as fluent interface
- See Also:
println(String)
-
println
Append the source string passed as argument to the buffer, then append a newline. If this is being appended at the beginning of a line, performs indentation first.The source line to be printed should not contain newline/carriage-return characters. If the source line passed as argument contains newline/carriage-return characters would impredictably affect a correct computation of the current
getCursor()
position.- Parameters:
arg
- source line to be printed (should not contain newline/carriage-return characters)- Returns:
- this instance, for nesting calls to method as fluent interface
-
println
Append a newline to the buffer.- Returns:
- this instance, for nesting calls to method as fluent interface
-
getCursor
Return the current cursor position (line, column) in the source printer buffer.Please notice in order to guarantee a correct computation of the cursor position, this printer expect the contracts of the methods
print(String)
andprintln(String)
has been respected through all method calls, meaning the source string passed as argument to those method calls did not contain newline/carriage-return characters.- Returns:
- the current cursor position (line, column).
-
getSource
Deprecated.use toString()- Returns:
- the currently printed source code.
-
toString
-
normalizeEolInTextBlock
Changes all EOL characters in "content" to the EOL character this SourcePrinter is using. -
reindentWithAlignToCursor
public void reindentWithAlignToCursor()Set the top-most indent to the column the cursor is currently in, can be undone withreindentToPreviousLevel()
. Does not actually output anything. -
reindentToPreviousLevel
public void reindentToPreviousLevel()Set the top-most indent to the column the cursor was before the lastreindentWithAlignToCursor()
call. Does not actually output anything. -
duplicateIndent
public void duplicateIndent()Adds an indent to the top of the stack that is a copy of the current top indent. With this you announce "I'm going to indent the next line(s)" but not how far yet. Once you do know, you can pop this indent ("unindent") and indent to the right column. (Does not actually output anything.)
-