Class Formatter

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.AutoCloseable

    public final class Formatter
    extends java.lang.Object
    implements java.io.Serializable, java.lang.AutoCloseable
    Formatter which performs the full formatting.
    See Also:
    Serialized Form
    • Field Detail

      • NO_FILE_SENTINEL

        public static final java.io.File NO_FILE_SENTINEL
        This Sentinel reference may be used to pass string content to a Formatter or FormatterStep when there is no actual File to format
    • Method Detail

      • getName

        public java.lang.String getName()
      • getEncoding

        public java.nio.charset.Charset getEncoding()
      • getRootDir

        public java.nio.file.Path getRootDir()
      • isClean

        public boolean isClean​(java.io.File file)
                        throws java.io.IOException
        Returns true iff the given file's formatting is up-to-date.
        Throws:
        java.io.IOException
      • applyTo

        public void applyTo​(java.io.File file)
                     throws java.io.IOException
        Applies formatting to the given file.
        Throws:
        java.io.IOException
      • applyToAndReturnResultIfDirty

        @Nullable
        public java.lang.String applyToAndReturnResultIfDirty​(java.io.File file)
                                                       throws java.io.IOException
        Applies formatting to the given file. Returns null if the file was already clean, or the formatted result with unix newlines if it was not.
        Throws:
        java.io.IOException
      • computeLineEndings

        public java.lang.String computeLineEndings​(java.lang.String unix,
                                                   java.io.File file)
        Applies the appropriate line endings to the given unix content.
      • compute

        public java.lang.String compute​(java.lang.String unix,
                                        java.io.File file)
        Returns the result of calling all of the FormatterSteps. The input must have unix line endings, and the output is guaranteed to also have unix line endings.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable