Skip to content

Commit 15670fa

Browse files
committed
Route all the FormatterStep.create through FormatterStepSerializationRoundtrip.
1 parent e9962c5 commit 15670fa

File tree

4 files changed

+11
-160
lines changed

4 files changed

+11
-160
lines changed

lib/src/main/java/com/diffplug/spotless/Formatter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,10 @@ public void close() {
312312

313313
/** This Sentinel reference may be used to pass string content to a Formatter or FormatterStep when there is no actual File to format */
314314
public static final File NO_FILE_SENTINEL = new File("NO_FILE_SENTINEL");
315+
316+
static void checkNotSentinel(File file) {
317+
if (file == Formatter.NO_FILE_SENTINEL) {
318+
throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile");
319+
}
320+
}
315321
}

lib/src/main/java/com/diffplug/spotless/FormatterFunc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void close() {
115115

116116
@Override
117117
public String apply(String unix, File file) throws Exception {
118-
FormatterStepImpl.checkNotSentinel(file);
118+
Formatter.checkNotSentinel(file);
119119
return function.apply(resource, unix, file);
120120
}
121121

@@ -144,7 +144,7 @@ interface NeedsFile extends FormatterFunc {
144144

145145
@Override
146146
default String apply(String unix, File file) throws Exception {
147-
FormatterStepImpl.checkNotSentinel(file);
147+
Formatter.checkNotSentinel(file);
148148
return applyWithFile(unix, file);
149149
}
150150

lib/src/main/java/com/diffplug/spotless/FormatterStep.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,6 @@ default FormatterStep filterByFile(SerializableFileFilter filter) {
7070
return new FilterByFileFormatterStep(this, filter);
7171
}
7272

73-
/**
74-
* Implements a FormatterStep in a strict way which guarantees correct and lazy implementation
75-
* of up-to-date checks. This maximizes performance for cases where the FormatterStep is not
76-
* actually needed (e.g. don't load eclipse setting file unless this step is actually running)
77-
* while also ensuring that Gradle can detect changes in a step's settings to determine that
78-
* it needs to rerun a format.
79-
*/
80-
abstract class Strict<State extends Serializable> extends LazyForwardingEquality<State> implements FormatterStep {
81-
private static final long serialVersionUID = 1L;
82-
83-
/**
84-
* Implements the formatting function strictly in terms
85-
* of the input data and the result of {@link #calculateState()}.
86-
*/
87-
protected abstract String format(State state, String rawUnix, File file) throws Exception;
88-
89-
@Override
90-
public final String format(String rawUnix, File file) throws Exception {
91-
return format(state(), rawUnix, file);
92-
}
93-
}
94-
9573
/**
9674
* @param name
9775
* The name of the formatter step.
@@ -151,8 +129,8 @@ static <RoundtripState extends Serializable, EqualityState extends Serializable>
151129
static <State extends Serializable> FormatterStep createLazy(
152130
String name,
153131
ThrowingEx.Supplier<State> stateSupplier,
154-
ThrowingEx.Function<State, FormatterFunc> stateToFormatter) {
155-
return new FormatterStepImpl.Standard<>(name, stateSupplier, stateToFormatter);
132+
SerializedFunction<State, FormatterFunc> stateToFormatter) {
133+
return createLazy(name, stateSupplier, SerializedFunction.identity(), stateToFormatter);
156134
}
157135

158136
/**
@@ -168,7 +146,7 @@ static <State extends Serializable> FormatterStep createLazy(
168146
static <State extends Serializable> FormatterStep create(
169147
String name,
170148
State state,
171-
ThrowingEx.Function<State, FormatterFunc> stateToFormatter) {
149+
SerializedFunction<State, FormatterFunc> stateToFormatter) {
172150
Objects.requireNonNull(state, "state");
173151
return createLazy(name, () -> state, stateToFormatter);
174152
}

lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)