Package com.squareup.javapoet
Class LineWrapper
java.lang.Object
com.squareup.javapoet.LineWrapper
Implements soft line wrapping on an appendable. To use, append characters using
append(java.lang.String)
or soft-wrapping spaces using wrappingSpace(int)
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
(package private) static final class
A delegatingAppendable
that records info about the chars passing through it. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringBuilder
Characters written since the last wrapping space that haven't yet been flushed.private boolean
private int
The number of characters since the most recent newline.private final int
private final String
private int
-1 if we have no buffering; otherwise the number ofindent
s to write after wrapping.private LineWrapper.FlushType
Null if we have no buffering; otherwise the type to pass to the next call toflush(com.squareup.javapoet.LineWrapper.FlushType)
.private final LineWrapper.RecordingAppendable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
Emits
.(package private) void
close()
Flush any outstanding text and forbid future writes to this line wrapper.private void
flush
(LineWrapper.FlushType flushType) Write the space followed by any buffered text that follows it.(package private) char
lastChar()
(package private) void
wrappingSpace
(int indentLevel) Emit either a space or a newline character.(package private) void
zeroWidthSpace
(int indentLevel) Emit a newline character if the line will exceed it's limit, otherwise do nothing.
-
Field Details
-
out
-
indent
-
columnLimit
private final int columnLimit -
closed
private boolean closed -
buffer
Characters written since the last wrapping space that haven't yet been flushed. -
column
private int columnThe 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 ofindent
s to write after wrapping. -
nextFlush
Null if we have no buffering; otherwise the type to pass to the next call toflush(com.squareup.javapoet.LineWrapper.FlushType)
.
-
-
Constructor Details
-
LineWrapper
LineWrapper(Appendable out, String indent, int columnLimit)
-
-
Method Details
-
lastChar
char lastChar()- Returns:
- the last emitted char or
Character.MIN_VALUE
if nothing emitted yet.
-
append
Emits
. This may be buffered to permit line wraps to be inserted.- Throws:
IOException
-
wrappingSpace
Emit either a space or a newline character.- Throws:
IOException
-
zeroWidthSpace
Emit a newline character if the line will exceed it's limit, otherwise do nothing.- Throws:
IOException
-
close
Flush any outstanding text and forbid future writes to this line wrapper.- Throws:
IOException
-
flush
Write the space followed by any buffered text that follows it.- Throws:
IOException
-