Package com.diffplug.spotless
Interface FormatterStep
-
- All Superinterfaces:
java.io.Serializable
- All Known Implementing Classes:
FormatterStep.Strict
public interface FormatterStep extends java.io.SerializableAn implementation of this class specifies a single step in a formatting process. The input is guaranteed to have unix-style newlines, and the output is required to not introduce any windows-style newlines as well.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classFormatterStep.Strict<State extends java.io.Serializable>Implements a FormatterStep in a strict way which guarantees correct and lazy implementation of up-to-date checks.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description static <State extends java.io.Serializable>
FormatterStepcreate(java.lang.String name, State state, ThrowingEx.Function<State,FormatterFunc> stateToFormatter)static <State extends java.io.Serializable>
FormatterStepcreateLazy(java.lang.String name, ThrowingEx.Supplier<State> stateSupplier, ThrowingEx.Function<State,FormatterFunc> stateToFormatter)static FormatterStepcreateNeverUpToDate(java.lang.String name, FormatterFunc function)static FormatterStepcreateNeverUpToDateLazy(java.lang.String name, ThrowingEx.Supplier<FormatterFunc> functionSupplier)default FormatterStepfilterByContent(OnMatch onMatch, java.lang.String contentPattern)Returns a newFormatterStepwhich, observing the value offormatIfMatches, will only apply, or not, its changes to files which pass the given filter.default FormatterStepfilterByContentPattern(java.lang.String contentPattern)Deprecated.default FormatterStepfilterByFile(SerializableFileFilter filter)Returns a new FormatterStep which will only apply its changes to files which pass the given filter.java.lang.Stringformat(java.lang.String rawUnix, java.io.File file)Returns a formatted version of the given content.java.lang.StringgetName()The name of the step, for debugging purposes.
-
-
-
Method Detail
-
getName
java.lang.String getName()
The name of the step, for debugging purposes.
-
format
@Nullable java.lang.String format(java.lang.String rawUnix, java.io.File file) throws java.lang.ExceptionReturns a formatted version of the given content.- Parameters:
rawUnix- the content to format, guaranteed to have unix-style newlines ('\n'); never nullfile- the file whichrawUnixwas obtained from; never null. Pass the referenceFormatter.NO_FILE_SENTINELif and only if no file is actually associated withrawUnix- Returns:
- the formatted content, guaranteed to only have unix-style newlines; may return null if the formatter step doesn't have any changes to make
- Throws:
java.lang.Exception- if the formatter step experiences a problem
-
filterByContentPattern
@Deprecated default FormatterStep filterByContentPattern(java.lang.String contentPattern)
Deprecated.Returns a new FormatterStep which will only apply its changes to files which pass the given filter.- Parameters:
contentPattern- java regular expression used to filter out files which content doesn't contain pattern- Returns:
- FormatterStep
-
filterByContent
default FormatterStep filterByContent(OnMatch onMatch, java.lang.String contentPattern)
Returns a newFormatterStepwhich, observing the value offormatIfMatches, will only apply, or not, its changes to files which pass the given filter.- Parameters:
onMatch- determines if matches are included or excludedcontentPattern- java regular expression used to filter in or out files which content contain pattern- Returns:
- FormatterStep
-
filterByFile
default FormatterStep filterByFile(SerializableFileFilter filter)
Returns a new FormatterStep which will only apply its changes to files which pass the given filter. The provided filter must be serializable.
-
createLazy
static <State extends java.io.Serializable> FormatterStep createLazy(java.lang.String name, ThrowingEx.Supplier<State> stateSupplier, ThrowingEx.Function<State,FormatterFunc> stateToFormatter)
- Parameters:
name- The name of the formatter stepstateSupplier- If the rule has any state, this supplier will calculate it lazily, and the result will be passed to stateToFormatterstateToFormatter- A pure function which generates a formatting function using only the state supplied by state and nowhere else.- Returns:
- A FormatterStep
-
create
static <State extends java.io.Serializable> FormatterStep create(java.lang.String name, State state, ThrowingEx.Function<State,FormatterFunc> stateToFormatter)
- Parameters:
name- The name of the formatter stepstate- If the rule has any state, this state must contain all of itstateToFormatter- A pure function which generates a formatting function using only the state supplied by state and nowhere else.- Returns:
- A FormatterStep
-
createNeverUpToDateLazy
static FormatterStep createNeverUpToDateLazy(java.lang.String name, ThrowingEx.Supplier<FormatterFunc> functionSupplier)
- Parameters:
name- The name of the formatter stepfunctionSupplier- A supplier which will lazily generate the function used by the formatter step- Returns:
- A FormatterStep which will never report that it is up-to-date, because it is not equal to the serialized representation of itself.
-
createNeverUpToDate
static FormatterStep createNeverUpToDate(java.lang.String name, FormatterFunc function)
- Parameters:
name- The name of the formatter stepfunction- The function used by the formatter step- Returns:
- A FormatterStep which will never report that it is up-to-date, because it is not equal to the serialized representation of itself.
-
-