Skip to content

Commit f5f6836

Browse files
committed
Use the new API.
1 parent 46635c6 commit f5f6836

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

lib/src/main/java/com/diffplug/spotless/generic/IndentStep.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616
package com.diffplug.spotless.generic;
1717

18+
import java.io.Serializable;
19+
1820
import com.diffplug.spotless.FormatterFunc;
1921
import com.diffplug.spotless.FormatterStep;
20-
import com.diffplug.spotless.FormatterStepEqualityOnStateSerialization;
22+
import com.diffplug.spotless.SerializedFunction;
2123

2224
/** Simple step which checks for consistent indentation characters. */
23-
public final class IndentStep extends FormatterStepEqualityOnStateSerialization<IndentStep> {
25+
public final class IndentStep implements Serializable {
2426
private static final long serialVersionUID = 1L;
2527

2628
final Type type;
@@ -31,21 +33,6 @@ private IndentStep(Type type, int numSpacesPerTab) {
3133
this.numSpacesPerTab = numSpacesPerTab;
3234
}
3335

34-
@Override
35-
public String getName() {
36-
return "indentWith" + type.tabSpace("Tabs", "Spaces");
37-
}
38-
39-
@Override
40-
protected IndentStep stateSupplier() {
41-
return this;
42-
}
43-
44-
@Override
45-
protected FormatterFunc stateToFormatter(IndentStep state) {
46-
return new Runtime(this)::format;
47-
}
48-
4936
private static final int DEFAULT_NUM_SPACES_PER_TAB = 4;
5037

5138
public enum Type {
@@ -68,7 +55,14 @@ public FormatterStep create(int numSpacesPerTab) {
6855

6956
/** Creates a step which will indent with the given type of whitespace, converting between tabs and spaces at the given ratio. */
7057
public static FormatterStep create(Type type, int numSpacesPerTab) {
71-
return new IndentStep(type, numSpacesPerTab);
58+
return FormatterStep.create("indentWith" + type.tabSpace("Tabs", "Spaces"),
59+
new IndentStep(type, numSpacesPerTab), SerializedFunction.identity(),
60+
IndentStep::startFormatting);
61+
}
62+
63+
private FormatterFunc startFormatting() {
64+
var runtime = new Runtime(this);
65+
return runtime::format;
7266
}
7367

7468
static class Runtime {

lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.diffplug.spotless.*;
2626

2727
/** Wraps up <a href="https://github.com/cqfn/diKTat">diktat</a> as a FormatterStep. */
28-
public class DiktatStep extends FormatterStepEqualityOnStateSerialization<DiktatStep.State> {
28+
public class DiktatStep implements Serializable {
2929
private static final long serialVersionUID = 1L;
3030
private final JarState.Promised jarState;
3131
private final boolean isScript;
@@ -66,26 +66,16 @@ public static FormatterStep create(String versionDiktat, Provisioner provisioner
6666
}
6767
Objects.requireNonNull(versionDiktat, "versionDiktat");
6868
Objects.requireNonNull(provisioner, "provisioner");
69-
return new DiktatStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + versionDiktat, provisioner)), isScript, config);
69+
return FormatterStep.create(NAME,
70+
new DiktatStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + versionDiktat, provisioner)), isScript, config),
71+
DiktatStep::equalityState, State::createFormat);
7072
}
7173

72-
@Override
73-
public String getName() {
74-
return NAME;
75-
}
76-
77-
@Override
78-
protected State stateSupplier() throws Exception {
74+
private State equalityState() throws Exception {
7975
return new State(jarState.get(), isScript, FileSignature.stripAbsolutePathsNullable(config));
8076
}
8177

82-
@Override
83-
protected FormatterFunc stateToFormatter(State state) throws Exception {
84-
return state.createFormat();
85-
}
86-
8778
static final class State implements Serializable {
88-
8979
private static final long serialVersionUID = 1L;
9080

9181
final JarState jar;

0 commit comments

Comments
 (0)