Package com.google.googlejavaformat.java
Class JavaOutput
- java.lang.Object
-
- com.google.googlejavaformat.InputOutput
-
- com.google.googlejavaformat.Output
-
- com.google.googlejavaformat.java.JavaOutput
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.googlejavaformat.Output
Output.BreakTag
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,OpsBuilder.BlankLineWanted>blankLinesprivate CommentsHelpercommentsHelperprivate intiLineprivate InputjavaInputprivate intkNprivate intlastKprivate java.lang.StringBuilderlineBuilderprivate java.lang.StringlineSeparatorprivate java.util.List<java.lang.String>mutableLinesprivate intnewlinesPendingprivate com.google.common.collect.RangeSet<java.lang.Integer>partialFormatRangesprivate java.lang.StringBuilderspacesPending-
Fields inherited from class com.google.googlejavaformat.InputOutput
EMPTY_RANGE, ranges
-
-
Constructor Summary
Constructors Constructor Description JavaOutput(java.lang.String lineSeparator, Input javaInput, CommentsHelper commentsHelper)JavaOutputconstructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(java.lang.String text, com.google.common.collect.Range<java.lang.Integer> range)Output a string.static java.lang.StringapplyReplacements(java.lang.String input, java.util.List<Replacement> replacements)voidblankLine(int k, OpsBuilder.BlankLineWanted wanted)A blank line is or is not wanted here.static Input.TokendTok(Input.Token token)The last non-whitespace Tok in the Token.private com.google.common.collect.Range<java.lang.Integer>expandToBreakableRegions(com.google.common.collect.Range<java.lang.Integer> iRange)Expand a token range to start and end on acceptable boundaries for re-formatting.voidflush()Flush any incomplete last line, then add the EOF token into our data structures.CommentsHelpergetCommentsHelper()Get theCommentsHelper.com.google.common.collect.ImmutableList<Replacement>getFormatReplacements(com.google.common.collect.RangeSet<java.lang.Integer> iRangeSet0)Emit a list ofReplacements to convert from input to output.voidindent(int indent)Indent by outputtingindentspaces.private booleanisComment(java.lang.String text)voidmarkForPartialFormat(Input.Token start, Input.Token end)Marks a region that can be partially formatted.static intstartPosition(Input.Token token)The earliest position of any Tok in the Token, including leading whitespace.static Input.TokstartTok(Input.Token token)The earliest non-whitespace Tok in the Token.java.lang.StringtoString()private static com.google.common.collect.Range<java.lang.Integer>union(com.google.common.collect.Range<java.lang.Integer> x, com.google.common.collect.Range<java.lang.Integer> y)-
Methods inherited from class com.google.googlejavaformat.InputOutput
computeRanges, getLine, getLineCount, getRanges, makeKToIJ, setLines
-
-
-
-
Field Detail
-
lineSeparator
private final java.lang.String lineSeparator
-
javaInput
private final Input javaInput
-
commentsHelper
private final CommentsHelper commentsHelper
-
blankLines
private final java.util.Map<java.lang.Integer,OpsBuilder.BlankLineWanted> blankLines
-
partialFormatRanges
private final com.google.common.collect.RangeSet<java.lang.Integer> partialFormatRanges
-
mutableLines
private final java.util.List<java.lang.String> mutableLines
-
kN
private final int kN
-
iLine
private int iLine
-
lastK
private int lastK
-
newlinesPending
private int newlinesPending
-
lineBuilder
private java.lang.StringBuilder lineBuilder
-
spacesPending
private java.lang.StringBuilder spacesPending
-
-
Constructor Detail
-
JavaOutput
public JavaOutput(java.lang.String lineSeparator, Input javaInput, CommentsHelper commentsHelper)JavaOutputconstructor.- Parameters:
javaInput- theInput, used to match up blank lines in the outputcommentsHelper- theCommentsHelper, used to rewrite comments
-
-
Method Detail
-
blankLine
public void blankLine(int k, OpsBuilder.BlankLineWanted wanted)Description copied from class:OutputA blank line is or is not wanted here.
-
markForPartialFormat
public void markForPartialFormat(Input.Token start, Input.Token end)
Description copied from class:OutputMarks a region that can be partially formatted.- Specified by:
markForPartialFormatin classOutput
-
append
public void append(java.lang.String text, com.google.common.collect.Range<java.lang.Integer> range)Description copied from class:OutputOutput a string.
-
indent
public void indent(int indent)
Description copied from class:OutputIndent by outputtingindentspaces.
-
flush
public void flush()
Flush any incomplete last line, then add the EOF token into our data structures.
-
getCommentsHelper
public CommentsHelper getCommentsHelper()
Description copied from class:OutputGet theCommentsHelper.- Specified by:
getCommentsHelperin classOutput- Returns:
- the
CommentsHelper
-
getFormatReplacements
public com.google.common.collect.ImmutableList<Replacement> getFormatReplacements(com.google.common.collect.RangeSet<java.lang.Integer> iRangeSet0)
Emit a list ofReplacements to convert from input to output.- Returns:
- a list of
Replacements, sorted by start index, without overlaps
-
expandToBreakableRegions
private com.google.common.collect.Range<java.lang.Integer> expandToBreakableRegions(com.google.common.collect.Range<java.lang.Integer> iRange)
Expand a token range to start and end on acceptable boundaries for re-formatting.- Parameters:
iRange- theRangeof tokens- Returns:
- the expanded token range
-
applyReplacements
public static java.lang.String applyReplacements(java.lang.String input, java.util.List<Replacement> replacements)
-
startPosition
public static int startPosition(Input.Token token)
The earliest position of any Tok in the Token, including leading whitespace.
-
startTok
public static Input.Tok startTok(Input.Token token)
The earliest non-whitespace Tok in the Token.
-
endTok
public static Input.Tok endTok(Input.Token token)
The last non-whitespace Tok in the Token.
-
isComment
private boolean isComment(java.lang.String text)
-
union
private static com.google.common.collect.Range<java.lang.Integer> union(com.google.common.collect.Range<java.lang.Integer> x, com.google.common.collect.Range<java.lang.Integer> y)
-
-