Skip to content

Commit 48e744d

Browse files
committed
Remove crufty and internally-unused methods from Formatter.
1 parent add4c1e commit 48e744d

File tree

2 files changed

+1
-65
lines changed

2 files changed

+1
-65
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
3434
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))
3535
* **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954))
3636
* **BREAKING** Fully removed `Rome`, use `Biome` instead. ([#2119](https://github.com/diffplug/spotless/pull/2119))
37+
* **BREAKING** Removed `isClean`, `applyTo`, and `applyToAndReturnResultIfDirty` from `Formatter` because users should instead use `PaddedCell.check()`.
3738

3839
## [2.45.0] - 2024-01-23
3940
### Added

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

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@
2424
import java.io.ObjectStreamException;
2525
import java.io.Serializable;
2626
import java.nio.charset.Charset;
27-
import java.nio.file.Files;
2827
import java.nio.file.Path;
2928
import java.nio.file.Paths;
30-
import java.nio.file.StandardOpenOption;
3129
import java.util.ArrayList;
32-
import java.util.Arrays;
3330
import java.util.List;
3431
import java.util.Objects;
3532

36-
import javax.annotation.Nullable;
37-
3833
/** Formatter which performs the full formatting. */
3934
public final class Formatter implements Serializable, AutoCloseable {
4035
private static final long serialVersionUID = 1L;
@@ -159,66 +154,6 @@ public Formatter build() {
159154
}
160155
}
161156

162-
/** Returns true iff the given file's formatting is up-to-date. */
163-
public boolean isClean(File file) throws IOException {
164-
Objects.requireNonNull(file);
165-
166-
String raw = new String(Files.readAllBytes(file.toPath()), encoding);
167-
String unix = LineEnding.toUnix(raw);
168-
169-
// check the newlines (we can find these problems without even running the steps)
170-
int totalNewLines = (int) unix.codePoints().filter(val -> val == '\n').count();
171-
int windowsNewLines = raw.length() - unix.length();
172-
if (lineEndingsPolicy.isUnix(file)) {
173-
if (windowsNewLines != 0) {
174-
return false;
175-
}
176-
} else {
177-
if (windowsNewLines != totalNewLines) {
178-
return false;
179-
}
180-
}
181-
182-
// check the other formats
183-
String formatted = compute(unix, file);
184-
185-
// return true iff the formatted string equals the unix one
186-
return formatted.equals(unix);
187-
}
188-
189-
/** Applies formatting to the given file. */
190-
public void applyTo(File file) throws IOException {
191-
applyToAndReturnResultIfDirty(file);
192-
}
193-
194-
/**
195-
* Applies formatting to the given file.
196-
* <p>
197-
* Returns null if the file was already clean, or the
198-
* formatted result with unix newlines if it was not.
199-
*/
200-
public @Nullable String applyToAndReturnResultIfDirty(File file) throws IOException {
201-
Objects.requireNonNull(file);
202-
203-
byte[] rawBytes = Files.readAllBytes(file.toPath());
204-
String raw = new String(rawBytes, encoding);
205-
String rawUnix = LineEnding.toUnix(raw);
206-
207-
// enforce the format
208-
String formattedUnix = compute(rawUnix, file);
209-
// enforce the line endings
210-
String formatted = computeLineEndings(formattedUnix, file);
211-
212-
// write out the file iff it has changed
213-
byte[] formattedBytes = formatted.getBytes(encoding);
214-
if (!Arrays.equals(rawBytes, formattedBytes)) {
215-
Files.write(file.toPath(), formattedBytes, StandardOpenOption.TRUNCATE_EXISTING);
216-
return formattedUnix;
217-
} else {
218-
return null;
219-
}
220-
}
221-
222157
/** Applies the appropriate line endings to the given unix content. */
223158
public String computeLineEndings(String unix, File file) {
224159
Objects.requireNonNull(unix, "unix");

0 commit comments

Comments
 (0)