Package com.google.googlejavaformat.java
Class StringWrapper
java.lang.Object
com.google.googlejavaformat.java.StringWrapper
Wraps string literals that exceed the column limit.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.google.common.base.CharMatcherprivate static final Method -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringapplyReplacements(String javaInput, com.google.common.collect.TreeRangeMap<Integer, String> replacementMap) Applies replacements to the given string.private static List<com.sun.source.tree.Tree> flatten(String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, com.sun.source.util.TreePath path, com.sun.source.util.TreePath parent, 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) getReflowReplacements(int columnLimit, String input) private static intgetStartPosition(com.sun.source.tree.Tree tree) private static @Nullable Method(package private) static inthasEscapedNewlineAt(String input, int idx) (package private) static inthasEscapedWhitespaceAt(String input, int idx) private static booleanneedWrapping(int columnLimit, 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(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.JCCompilationUnitParses the given Java source.private static Stringreflow(String separator, int columnLimit, int startColumn, int trailing, com.google.common.collect.ImmutableList<String> components, boolean first0) Reflows the given source text, trying to split on word boundaries.private static com.google.common.collect.ImmutableList<String> stringComponents(String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, 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 StringstripIndent(String input) (package private) static StringReflows string literals in the given Java source code that extend past the given column limit.static StringReflows long string literals in the given Java source code.
-
Field Details
-
STRIP_INDENT
-
STRING_CONCAT_DELIMITER
public static final com.google.common.base.CharMatcher STRING_CONCAT_DELIMITER
-
-
Constructor Details
-
StringWrapper
private StringWrapper()
-
-
Method Details
-
wrap
Reflows long string literals in the given Java source code.- Throws:
FormatterException
-
wrap
Reflows 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<Integer,String> getReflowReplacements(int columnLimit, String input) throws FormatterException - Throws:
FormatterException
-
getStripIndent
-
stripIndent
-
stringComponents
private static com.google.common.collect.ImmutableList<String> stringComponents(String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, 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
-
hasEscapedNewlineAt
-
reflow
private static String reflow(String separator, int columnLimit, int startColumn, int trailing, com.google.common.collect.ImmutableList<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 List<com.sun.source.tree.Tree> flatten(String input, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, com.sun.source.util.TreePath path, com.sun.source.util.TreePath parent, 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(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
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(String source, boolean allowStringFolding) throws FormatterException Parses the given Java source.- Throws:
FormatterException
-
applyReplacements
private static String applyReplacements(String javaInput, com.google.common.collect.TreeRangeMap<Integer, String> replacementMap) throws FormatterExceptionApplies replacements to the given string.- Throws:
FormatterException
-