Package com.diffplug.spotless
Interface FormatterStep
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Serializable
- All Known Implementing Classes:
FenceStep.BaseStep
public interface FormatterStep extends java.io.Serializable, java.lang.AutoCloseable
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.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <RoundtripState extends java.io.Serializable,EqualityState extends java.io.Serializable>
FormatterStepcreate(java.lang.String name, RoundtripState roundTrip, SerializedFunction<RoundtripState,EqualityState> equalityFunc, SerializedFunction<EqualityState,FormatterFunc> formatterFunc)
static <State extends java.io.Serializable>
FormatterStepcreate(java.lang.String name, State state, SerializedFunction<State,FormatterFunc> stateToFormatter)
static <RoundtripState extends java.io.Serializable,EqualityState extends java.io.Serializable>
FormatterStepcreateLazy(java.lang.String name, ThrowingEx.Supplier<RoundtripState> roundtripInit, SerializedFunction<RoundtripState,EqualityState> equalityFunc, SerializedFunction<EqualityState,FormatterFunc> formatterFunc)
static <State extends java.io.Serializable>
FormatterStepcreateLazy(java.lang.String name, ThrowingEx.Supplier<State> stateSupplier, SerializedFunction<State,FormatterFunc> stateToFormatter)
default FormatterStep
filterByContent(OnMatch onMatch, java.lang.String contentPattern)
Returns a newFormatterStep
which, observing the value offormatIfMatches
, will only apply, or not, 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
-
filterByContent
default FormatterStep filterByContent(OnMatch onMatch, java.lang.String contentPattern)
Returns a newFormatterStep
which, 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 <RoundtripState extends java.io.Serializable,EqualityState extends java.io.Serializable> FormatterStep createLazy(java.lang.String name, ThrowingEx.Supplier<RoundtripState> roundtripInit, SerializedFunction<RoundtripState,EqualityState> equalityFunc, SerializedFunction<EqualityState,FormatterFunc> formatterFunc)
- Parameters:
name
- The name of the formatter step.roundtripInit
- If the step has any state, this supplier will calculate it lazily. The supplier doesn't have to be serializable, but the result it calculates needs to be serializable.equalityFunc
- A pure serializable function (method reference recommended) which takes the result of `roundtripInit`, and returns a serializable object whose serialized representation will be used for `.equals` and `.hashCode` of the FormatterStep.formatterFunc
- A pure serializable function (method reference recommended) which takes the result of `equalityFunc`, and returns a `FormatterFunc` which will be used for the actual formatting.- Returns:
- A FormatterStep which can be losslessly roundtripped through the java serialization machinery.
-
create
static <RoundtripState extends java.io.Serializable,EqualityState extends java.io.Serializable> FormatterStep create(java.lang.String name, RoundtripState roundTrip, SerializedFunction<RoundtripState,EqualityState> equalityFunc, SerializedFunction<EqualityState,FormatterFunc> formatterFunc)
- Parameters:
name
- The name of the formatter step.roundTrip
- The roundtrip serializable state of the step.equalityFunc
- A pure serializable function (method reference recommended) which takes the result of `roundTrip`, and returns a serializable object whose serialized representation will be used for `.equals` and `.hashCode` of the FormatterStep.formatterFunc
- A pure serializable function (method reference recommended) which takes the result of `equalityFunc`, and returns a `FormatterFunc` which will be used for the actual formatting.- Returns:
- A FormatterStep which can be losslessly roundtripped through the java serialization machinery.
-
createLazy
static <State extends java.io.Serializable> FormatterStep createLazy(java.lang.String name, ThrowingEx.Supplier<State> stateSupplier, SerializedFunction<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, SerializedFunction<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
-
-