Package com.google.googlejavaformat.java
Class StringWrapper
- java.lang.Object
-
- com.google.googlejavaformat.java.StringWrapper
-
public final class StringWrapper extends java.lang.ObjectWraps string literals that exceed the column limit.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classStringWrapper.Reflower
-
Field Summary
Fields Modifier and Type Field Description static com.google.common.base.CharMatcherSTRING_CONCAT_DELIMITERprivate static java.lang.reflect.MethodSTRIP_INDENT
-
Constructor Summary
Constructors Modifier Constructor Description privateStringWrapper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringapplyReplacements(java.lang.String javaInput, com.google.common.collect.TreeRangeMap<java.lang.Integer,java.lang.String> replacementMap)Applies replacements to the given string.private static java.util.List<com.sun.source.tree.Tree>flatten(java.lang.String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, com.sun.source.util.TreePath path, com.sun.source.util.TreePath parent, java.util.concurrent.atomic.AtomicBoolean firstInChain)Flattens the given binary expression tree, and extracts the subset that contains the given path and any adjacent nodes that are also string literals.private static intgetEndPosition(com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, com.sun.source.tree.Tree tree)private static com.google.common.collect.TreeRangeMap<java.lang.Integer,java.lang.String>getReflowReplacements(int columnLimit, java.lang.String input)private static intgetStartPosition(com.sun.source.tree.Tree tree)private static @Nullable java.lang.reflect.MethodgetStripIndent()(package private) static inthasEscapedNewlineAt(java.lang.String input, int idx)(package private) static inthasEscapedWhitespaceAt(java.lang.String input, int idx)private static booleanneedWrapping(int columnLimit, java.lang.String input)Returns true if any lines in the given Java source exceed the column limit, or contain a"""that could indicate a text block.private static booleannoComments(java.lang.String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, com.sun.source.tree.Tree one, com.sun.source.tree.Tree two)private static com.sun.tools.javac.tree.JCTree.JCCompilationUnitparse(java.lang.String source, boolean allowStringFolding)Parses the given Java source.private static java.lang.Stringreflow(java.lang.String separator, int columnLimit, int startColumn, int trailing, com.google.common.collect.ImmutableList<java.lang.String> components, boolean first0)Reflows the given source text, trying to split on word boundaries.private static com.google.common.collect.ImmutableList<java.lang.String>stringComponents(java.lang.String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, java.util.List<com.sun.source.tree.Tree> flat)Returns the source text of the given string literal trees, excluding the leading and trailing double-quotes and the `+` operator.private static java.lang.StringstripIndent(java.lang.String input)(package private) static java.lang.Stringwrap(int columnLimit, java.lang.String input, Formatter formatter)Reflows string literals in the given Java source code that extend past the given column limit.static java.lang.Stringwrap(java.lang.String input, Formatter formatter)Reflows long string literals in the given Java source code.
-
-
-
Method Detail
-
wrap
public static java.lang.String wrap(java.lang.String input, Formatter formatter) throws FormatterExceptionReflows long string literals in the given Java source code.- Throws:
FormatterException
-
wrap
static java.lang.String wrap(int columnLimit, java.lang.String input, Formatter formatter) throws FormatterExceptionReflows string literals in the given Java source code that extend past the given column limit.- Throws:
FormatterException
-
getReflowReplacements
private static com.google.common.collect.TreeRangeMap<java.lang.Integer,java.lang.String> getReflowReplacements(int columnLimit, java.lang.String input) throws FormatterException- Throws:
FormatterException
-
getStripIndent
private static @Nullable java.lang.reflect.Method getStripIndent()
-
stripIndent
private static java.lang.String stripIndent(java.lang.String input)
-
stringComponents
private static com.google.common.collect.ImmutableList<java.lang.String> stringComponents(java.lang.String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, java.util.List<com.sun.source.tree.Tree> flat)Returns the source text of the given string literal trees, excluding the leading and trailing double-quotes and the `+` operator.
-
hasEscapedWhitespaceAt
static int hasEscapedWhitespaceAt(java.lang.String input, int idx)
-
hasEscapedNewlineAt
static int hasEscapedNewlineAt(java.lang.String input, int idx)
-
reflow
private static java.lang.String reflow(java.lang.String separator, int columnLimit, int startColumn, int trailing, com.google.common.collect.ImmutableList<java.lang.String> components, boolean first0)Reflows the given source text, trying to split on word boundaries.- Parameters:
separator- the line separatorcolumnLimit- the number of columns to wrap atstartColumn- the column position of the beginning of the original texttrailing- extra space to leave after the last line, to accommodate a ; or )components- the text to reflow. This is a list of “words” of a single literal. Its first and last quotes have been strippedfirst0- true if the text includes the beginning of its enclosing concat chain
-
flatten
private static java.util.List<com.sun.source.tree.Tree> flatten(java.lang.String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, com.sun.source.util.TreePath path, com.sun.source.util.TreePath parent, java.util.concurrent.atomic.AtomicBoolean firstInChain)Flattens the given binary expression tree, and extracts the subset that contains the given path and any adjacent nodes that are also string literals.
-
noComments
private static boolean noComments(java.lang.String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, com.sun.source.tree.Tree one, com.sun.source.tree.Tree two)
-
getEndPosition
private static int getEndPosition(com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, com.sun.source.tree.Tree tree)
-
getStartPosition
private static int getStartPosition(com.sun.source.tree.Tree tree)
-
needWrapping
private static boolean needWrapping(int columnLimit, java.lang.String input)Returns true if any lines in the given Java source exceed the column limit, or contain a"""that could indicate a text block.
-
parse
private static com.sun.tools.javac.tree.JCTree.JCCompilationUnit parse(java.lang.String source, boolean allowStringFolding) throws FormatterExceptionParses the given Java source.- Throws:
FormatterException
-
applyReplacements
private static java.lang.String applyReplacements(java.lang.String javaInput, com.google.common.collect.TreeRangeMap<java.lang.Integer,java.lang.String> replacementMap) throws FormatterExceptionApplies replacements to the given string.- Throws:
FormatterException
-
-