Skip to content

Commit 4439934

Browse files
committed
Rely on existing Sentinel
1 parent 378a4e8 commit 4439934

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
public final class Formatter implements Serializable, AutoCloseable {
4040
private static final long serialVersionUID = 1L;
4141

42-
// This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format
43-
public static final File SENTINEL_NO_FILE_ON_DISK = new File("NO_FILE_ON_DISK.sentinel");
44-
4542
private LineEnding.Policy lineEndingsPolicy;
4643
private Charset encoding;
4744
private Path rootDir;
@@ -240,7 +237,7 @@ public String compute(String unix, File file) {
240237
unix = LineEnding.toUnix(formatted);
241238
}
242239
} catch (Throwable e) {
243-
if (file == SENTINEL_NO_FILE_ON_DISK) {
240+
if (file == FormatterStepImpl.SENTINEL) {
244241
exceptionPolicy.handleError(e, step, "");
245242
} else {
246243
// Path may be forged from a different FileSystem than Filesystem.default

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2021 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.
@@ -127,7 +127,7 @@ public String apply(String unix, File file) throws Exception {
127127

128128
@Override
129129
public String apply(String unix) throws Exception {
130-
return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK);
130+
return apply(unix, FormatterStepImpl.SENTINEL);
131131
}
132132
};
133133
}
@@ -156,7 +156,7 @@ default String apply(String unix, File file) throws Exception {
156156

157157
@Override
158158
default String apply(String unix) throws Exception {
159-
return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK);
159+
return apply(unix, FormatterStepImpl.SENTINEL);
160160
}
161161
}
162162
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface FormatterStep extends Serializable {
3838
* the content to format, guaranteed to have unix-style newlines ('\n'); never null
3939
* @param file
4040
* the file which {@code rawUnix} was obtained from; never null. Pass the reference
41-
* {@code Formatter#SENTINEL_NO_FILE_ON_DISK} if and only if no file is actually associated with {@code rawUnix}
41+
* {@code FormatterStepImpl#SENTINEL} if and only if no file is actually associated with {@code rawUnix}
4242
* @return the formatted content, guaranteed to only have unix-style newlines; may return null
4343
* if the formatter step doesn't have any changes to make
4444
* @throws Exception if the formatter step experiences a problem

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,18 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti
109109
if (formatter == null) {
110110
formatter = formatterSupplier.get();
111111
if (formatter instanceof FormatterFunc.Closeable) {
112-
throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284");
112+
throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284");
113113
}
114114
}
115115
return formatter.apply(rawUnix, file);
116116
}
117117
}
118118

119+
/**This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format */
120+
public static final File SENTINEL = new File("");
121+
119122
static void checkNotSentinel(File file) {
120-
if (file == Formatter.SENTINEL_NO_FILE_ON_DISK) {
123+
if (file == SENTINEL) {
121124
throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile");
122125
}
123126
}

0 commit comments

Comments
 (0)