Package com.squareup.javapoet
Class LineWrapper
- java.lang.Object
-
- com.squareup.javapoet.LineWrapper
-
final class LineWrapper extends java.lang.Object
Implements 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 class
LineWrapper.FlushType
(package private) static class
LineWrapper.RecordingAppendable
A delegatingAppendable
that records info about the chars passing through it.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuilder
buffer
Characters written since the last wrapping space that haven't yet been flushed.private boolean
closed
private int
column
The number of characters since the most recent newline.private int
columnLimit
private java.lang.String
indent
private int
indentLevel
-1 if we have no buffering; otherwise the number ofindent
s to write after wrapping.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)
.private LineWrapper.RecordingAppendable
out
-
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) void
append(java.lang.String s)
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 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 ofindent
s 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_VALUE
if nothing emitted yet.
-
append
void append(java.lang.String s) throws java.io.IOException
Emits
. This may be buffered to permit line wraps to be inserted.- Throws:
java.io.IOException
-
wrappingSpace
void wrappingSpace(int indentLevel) throws java.io.IOException
Emit either a space or a newline character.- Throws:
java.io.IOException
-
zeroWidthSpace
void zeroWidthSpace(int indentLevel) throws java.io.IOException
Emit a newline character if the line will exceed it's limit, otherwise do nothing.- Throws:
java.io.IOException
-
close
void close() throws java.io.IOException
Flush 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
-
-