Package com.diffplug.spotless
Class Formatter
- java.lang.Object
-
- com.diffplug.spotless.Formatter
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.AutoCloseable
public final class Formatter extends java.lang.Object implements java.io.Serializable, java.lang.AutoCloseableFormatter which performs the full formatting.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFormatter.Builder
-
Field Summary
Fields Modifier and Type Field Description static java.io.FileNO_FILE_SENTINELThis Sentinel reference may be used to pass string content to a Formatter or FormatterStep when there is no actual File to format
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyTo(java.io.File file)Applies formatting to the given file.java.lang.StringapplyToAndReturnResultIfDirty(java.io.File file)Applies formatting to the given file.static Formatter.Builderbuilder()voidclose()java.lang.Stringcompute(java.lang.String unix, java.io.File file)Returns the result of calling all of the FormatterSteps.java.lang.StringcomputeLineEndings(java.lang.String unix, java.io.File file)Applies the appropriate line endings to the given unix content.booleanequals(java.lang.Object obj)java.nio.charset.CharsetgetEncoding()FormatExceptionPolicygetExceptionPolicy()LineEnding.PolicygetLineEndingsPolicy()java.lang.StringgetName()java.nio.file.PathgetRootDir()java.util.List<FormatterStep>getSteps()inthashCode()booleanisClean(java.io.File file)Returns true iff the given file's formatting is up-to-date.
-
-
-
Method Detail
-
getName
public java.lang.String getName()
-
getLineEndingsPolicy
public LineEnding.Policy getLineEndingsPolicy()
-
getEncoding
public java.nio.charset.Charset getEncoding()
-
getRootDir
public java.nio.file.Path getRootDir()
-
getSteps
public java.util.List<FormatterStep> getSteps()
-
getExceptionPolicy
public FormatExceptionPolicy getExceptionPolicy()
-
builder
public static Formatter.Builder builder()
-
isClean
public boolean isClean(java.io.File file) throws java.io.IOExceptionReturns 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.IOExceptionApplies formatting to the given file.- Throws:
java.io.IOException
-
applyToAndReturnResultIfDirty
@Nullable public java.lang.String applyToAndReturnResultIfDirty(java.io.File file) throws java.io.IOExceptionApplies 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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
-