Package com.diffplug.spotless
Interface FormatterStep
-
- All Superinterfaces:
java.io.Serializable
- All Known Implementing Classes:
FormatterStep.Strict
public interface FormatterStep extends java.io.Serializable
An 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 class
FormatterStep.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 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 FormatterStep
createNeverUpToDate(java.lang.String name, FormatterFunc function)
static FormatterStep
createNeverUpToDateLazy(java.lang.String name, ThrowingEx.Supplier<FormatterFunc> functionSupplier)
default FormatterStep
filterByContentPattern(java.lang.String contentPattern)
Returns a new FormatterStep which will only apply its changes to files which pass the given filter.default FormatterStep
filterByFile(SerializableFileFilter filter)
Returns a new FormatterStep which will only apply its changes to files which pass the given filter.java.lang.String
format(java.lang.String rawUnix, java.io.File file)
Returns a formatted version of the given content.java.lang.String
getName()
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.Exception
Returns a formatted version of the given content.- Parameters:
rawUnix
- the content to format, guaranteed to have unix-style newlines ('\n'); never nullfile
- the file whichrawUnix
was obtained from; never null. Pass the referenceFormatter.NO_FILE_SENTINEL
if 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
default FormatterStep filterByContentPattern(java.lang.String contentPattern)
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
-
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.
-
-