Skip to content

Commit b3462c2

Browse files
committed
Remove FormatterStep.Strict, an unnecessary implementation detail.
1 parent 3ee9093 commit b3462c2

File tree

3 files changed

+24
-41
lines changed

3 files changed

+24
-41
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1111

1212
## [TBD lint release]
1313
* **BREAKING** Removed `isClean`, `applyTo`, and `applyToAndReturnResultIfDirty` from `Formatter` because users should instead use `PaddedCell.check()`.
14+
* **BREAKING** Removed `FormatterStep.Strict` because it was unnecessary and unused implementation detail.
1415

1516
## [Unreleased]
1617
### Changed

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,28 +67,6 @@ public default FormatterStep filterByFile(SerializableFileFilter filter) {
6767
return new FilterByFileFormatterStep(this, filter);
6868
}
6969

70-
/**
71-
* Implements a FormatterStep in a strict way which guarantees correct and lazy implementation
72-
* of up-to-date checks. This maximizes performance for cases where the FormatterStep is not
73-
* actually needed (e.g. don't load eclipse setting file unless this step is actually running)
74-
* while also ensuring that gradle can detect changes in a step's settings to determine that
75-
* it needs to rerun a format.
76-
*/
77-
abstract class Strict<State extends Serializable> extends LazyForwardingEquality<State> implements FormatterStep {
78-
private static final long serialVersionUID = 1L;
79-
80-
/**
81-
* Implements the formatting function strictly in terms
82-
* of the input data and the result of {@link #calculateState()}.
83-
*/
84-
protected abstract String format(State state, String rawUnix, File file) throws Exception;
85-
86-
@Override
87-
public final String format(String rawUnix, File file) throws Exception {
88-
return format(state(), rawUnix, file);
89-
}
90-
}
91-
9270
/**
9371
* @param name
9472
* The name of the formatter step

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@
2020
import java.util.Objects;
2121
import java.util.Random;
2222

23-
import com.diffplug.spotless.FormatterStep.Strict;
24-
2523
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2624

2725
/**
@@ -32,7 +30,7 @@
3230
* from the API.
3331
*/
3432
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
35-
abstract class FormatterStepImpl<State extends Serializable> extends Strict<State> {
33+
abstract class FormatterStepImpl<State extends Serializable> extends LazyForwardingEquality<State> implements FormatterStep {
3634
private static final long serialVersionUID = 1L;
3735

3836
/** Transient because only the state matters. */
@@ -67,15 +65,19 @@ static final class Standard<State extends Serializable> extends FormatterStepImp
6765
this.stateToFormatter = Objects.requireNonNull(stateToFormatter);
6866
}
6967

68+
private FormatterFunc func() throws Exception {
69+
if (formatter != null) {
70+
return formatter;
71+
}
72+
formatter = stateToFormatter.apply(state());
73+
return formatter;
74+
}
75+
7076
@Override
71-
protected String format(State state, String rawUnix, File file) throws Exception {
72-
Objects.requireNonNull(state, "state");
77+
public String format(String rawUnix, File file) throws Exception {
7378
Objects.requireNonNull(rawUnix, "rawUnix");
7479
Objects.requireNonNull(file, "file");
75-
if (formatter == null) {
76-
formatter = stateToFormatter.apply(state());
77-
}
78-
return formatter.apply(rawUnix, file);
80+
return func().apply(rawUnix, file);
7981
}
8082

8183
void cleanupFormatterFunc() {
@@ -100,15 +102,17 @@ static class NeverUpToDate extends FormatterStepImpl<Integer> {
100102
this.formatterSupplier = Objects.requireNonNull(formatterSupplier, "formatterSupplier");
101103
}
102104

103-
@Override
104-
protected String format(Integer state, String rawUnix, File file) throws Exception {
105-
if (formatter == null) {
106-
formatter = formatterSupplier.get();
107-
if (formatter instanceof FormatterFunc.Closeable) {
108-
throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284");
109-
}
105+
private FormatterFunc func() throws Exception {
106+
if (formatter != null) {
107+
return formatter;
110108
}
111-
return formatter.apply(rawUnix, file);
109+
formatter = formatterSupplier.get();
110+
return formatter;
111+
}
112+
113+
@Override
114+
public String format(String rawUnix, File file) throws Exception {
115+
return func().apply(rawUnix, file);
112116
}
113117
}
114118

0 commit comments

Comments
 (0)