Package com.squareup.javapoet
Class LineWrapper
- java.lang.Object
-
- com.squareup.javapoet.LineWrapper
-
final class LineWrapper extends java.lang.ObjectImplements soft line wrapping on an appendable. To use, append characters usingappend(java.lang.String)or soft-wrapping spaces usingwrappingSpace(int).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classLineWrapper.FlushType(package private) static classLineWrapper.RecordingAppendableA delegatingAppendablethat records info about the chars passing through it.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuilderbufferCharacters written since the last wrapping space that haven't yet been flushed.private booleanclosedprivate intcolumnThe number of characters since the most recent newline.private intcolumnLimitprivate java.lang.Stringindentprivate intindentLevel-1 if we have no buffering; otherwise the number ofindents to write after wrapping.private LineWrapper.FlushTypenextFlushNull if we have no buffering; otherwise the type to pass to the next call toflush(com.squareup.javapoet.LineWrapper.FlushType).private LineWrapper.RecordingAppendableout
-
Constructor Summary
Constructors Constructor Description LineWrapper(java.lang.Appendable out, java.lang.String indent, int columnLimit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidappend(java.lang.String s)Emits.(package private) voidclose()Flush any outstanding text and forbid future writes to this line wrapper.private voidflush(LineWrapper.FlushType flushType)Write the space followed by any buffered text that follows it.(package private) charlastChar()(package private) voidwrappingSpace(int indentLevel)Emit either a space or a newline character.(package private) voidzeroWidthSpace(int indentLevel)Emit a newline character if the line will exceed it's limit, otherwise do nothing.
-
-
-
Field Detail
-
out
private final LineWrapper.RecordingAppendable out
-
indent
private final java.lang.String indent
-
columnLimit
private final int columnLimit
-
closed
private boolean closed
-
buffer
private final java.lang.StringBuilder buffer
Characters written since the last wrapping space that haven't yet been flushed.
-
column
private int column
The number of characters since the most recent newline. Includes both out and the buffer.
-
indentLevel
private int indentLevel
-1 if we have no buffering; otherwise the number ofindents to write after wrapping.
-
nextFlush
private LineWrapper.FlushType nextFlush
Null if we have no buffering; otherwise the type to pass to the next call toflush(com.squareup.javapoet.LineWrapper.FlushType).
-
-
Method Detail
-
lastChar
char lastChar()
- Returns:
- the last emitted char or
Character.MIN_VALUEif nothing emitted yet.
-
append
void append(java.lang.String s) throws java.io.IOExceptionEmits. This may be buffered to permit line wraps to be inserted.- Throws:
java.io.IOException
-
wrappingSpace
void wrappingSpace(int indentLevel) throws java.io.IOExceptionEmit either a space or a newline character.- Throws:
java.io.IOException
-
zeroWidthSpace
void zeroWidthSpace(int indentLevel) throws java.io.IOExceptionEmit a newline character if the line will exceed it's limit, otherwise do nothing.- Throws:
java.io.IOException
-
close
void close() throws java.io.IOExceptionFlush any outstanding text and forbid future writes to this line wrapper.- Throws:
java.io.IOException
-
flush
private void flush(LineWrapper.FlushType flushType) throws java.io.IOException
Write the space followed by any buffered text that follows it.- Throws:
java.io.IOException
-
-