Class SnippetFormatter


  • public class SnippetFormatter
    extends java.lang.Object
    Formats a subset of a compilation unit.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String createIndentationString​(int indentationLevel)  
      com.google.common.collect.ImmutableList<Replacement> format​(SnippetFormatter.SnippetKind kind, java.lang.String source, java.util.List<com.google.common.collect.Range<java.lang.Integer>> ranges, int initialIndent, boolean includeComments)
      Runs the Google Java formatter on the given source, with only the given ranges specified.
      private static com.google.common.collect.Range<java.lang.Integer> offsetRange​(com.google.common.collect.Range<java.lang.Integer> range, int offset)  
      private static java.util.List<com.google.common.collect.Range<java.lang.Integer>> offsetRanges​(java.util.List<com.google.common.collect.Range<java.lang.Integer>> ranges, int offset)  
      private SnippetFormatter.SnippetWrapper snippetWrapper​(SnippetFormatter.SnippetKind kind, java.lang.String source, int initialIndent)  
      private static java.util.List<Replacement> toReplacements​(java.lang.String source, java.lang.String replacement)
      Generates Replacements rewriting source to replacement, under the assumption that they differ in whitespace alone.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • formatter

        private final Formatter formatter
      • NOT_WHITESPACE

        private static final com.google.common.base.CharMatcher NOT_WHITESPACE
    • Constructor Detail

      • SnippetFormatter

        public SnippetFormatter()
    • Method Detail

      • createIndentationString

        public java.lang.String createIndentationString​(int indentationLevel)
      • offsetRange

        private static com.google.common.collect.Range<java.lang.Integer> offsetRange​(com.google.common.collect.Range<java.lang.Integer> range,
                                                                                      int offset)
      • offsetRanges

        private static java.util.List<com.google.common.collect.Range<java.lang.Integer>> offsetRanges​(java.util.List<com.google.common.collect.Range<java.lang.Integer>> ranges,
                                                                                                       int offset)
      • format

        public com.google.common.collect.ImmutableList<Replacement> format​(SnippetFormatter.SnippetKind kind,
                                                                           java.lang.String source,
                                                                           java.util.List<com.google.common.collect.Range<java.lang.Integer>> ranges,
                                                                           int initialIndent,
                                                                           boolean includeComments)
                                                                    throws FormatterException
        Runs the Google Java formatter on the given source, with only the given ranges specified.
        Throws:
        FormatterException
      • toReplacements

        private static java.util.List<Replacement> toReplacements​(java.lang.String source,
                                                                  java.lang.String replacement)
        Generates Replacements rewriting source to replacement, under the assumption that they differ in whitespace alone.