Package com.diffplug.spotless
Interface FormatterStep
- All Superinterfaces:
AutoCloseable
,Serializable
- All Known Implementing Classes:
SerializeToByteArrayHack
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
Modifier and TypeMethodDescriptionstatic <RoundtripState extends Serializable,
EqualityState extends Serializable>
FormatterStepcreate
(String name, RoundtripState roundTrip, SerializedFunction<RoundtripState, EqualityState> equalityFunc, SerializedFunction<EqualityState, ? extends FormatterFunc> formatterFunc) static <State extends Serializable>
FormatterStepcreate
(String name, State state, SerializedFunction<State, FormatterFunc> stateToFormatter) static <RoundtripState extends Serializable,
EqualityState extends Serializable>
FormatterStepcreateLazy
(String name, ThrowingEx.Supplier<RoundtripState> roundtripInit, SerializedFunction<RoundtripState, EqualityState> equalityFunc, SerializedFunction<EqualityState, ? extends FormatterFunc> formatterFunc) static <State extends Serializable>
FormatterStepcreateLazy
(String name, ThrowingEx.Supplier<State> stateSupplier, SerializedFunction<State, FormatterFunc> stateToFormatter) default FormatterStep
filterByContent
(OnMatch onMatch, 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.Returns a formatted version of the given content.getName()
The name of the step, for debugging purposes.Returns a list of lints against the given file contentMethods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
getName
String getName()The name of the step, for debugging purposes. -
format
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:
Exception
- if the formatter step experiences a problem
-
lint
Returns a list of lints against the given file content- Parameters:
content
- the content to checkfile
- the file whichcontent
was obtained from; never null. Pass an empty file usingnew File("")
if and only if no file is actually associated withcontent
- Returns:
- a list of lints
- Throws:
Exception
- if the formatter step experiences a problem
-
filterByContent
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
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 Serializable,EqualityState extends Serializable> FormatterStep createLazy(String name, ThrowingEx.Supplier<RoundtripState> roundtripInit, SerializedFunction<RoundtripState, EqualityState> equalityFunc, SerializedFunction<EqualityState, ? extends 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 Serializable,EqualityState extends Serializable> FormatterStep create(String name, RoundtripState roundTrip, SerializedFunction<RoundtripState, EqualityState> equalityFunc, SerializedFunction<EqualityState, ? extends 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 Serializable> FormatterStep createLazy(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 Serializable> FormatterStep create(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
-