Skip to content

Commit 07a57ff

Browse files
committed
Rename the sentinel and move it to Formatter.
1 parent 7f7cc49 commit 07a57ff

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public String compute(String unix, File file) {
237237
unix = LineEnding.toUnix(formatted);
238238
}
239239
} catch (Throwable e) {
240-
if (file == FormatterStepImpl.SENTINEL) {
240+
if (file == NO_FILE_SENTINEL) {
241241
exceptionPolicy.handleError(e, step, "");
242242
} else {
243243
// Path may be forged from a different FileSystem than Filesystem.default
@@ -289,4 +289,7 @@ public void close() {
289289
}
290290
}
291291
}
292+
293+
/** This Sentinel reference may be used to Formatter requires a File, while there is no actual File to format */
294+
public static final File NO_FILE_SENTINEL = new File("NO_FILE_SENTINEL");
292295
}

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-2021 DiffPlug
2+
* Copyright 2016-2023 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, FormatterStepImpl.SENTINEL);
130+
return apply(unix, Formatter.NO_FILE_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, FormatterStepImpl.SENTINEL);
159+
return apply(unix, Formatter.NO_FILE_SENTINEL);
160160
}
161161
}
162162
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,8 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti
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-
122119
static void checkNotSentinel(File file) {
123-
if (file == SENTINEL) {
120+
if (file == Formatter.NO_FILE_SENTINEL) {
124121
throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile");
125122
}
126123
}

testlib/src/main/java/com/diffplug/spotless/StepHarness.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public AbstractStringAssert<?> testResourceExceptionMsg(String resourceBefore) {
8888

8989
public AbstractStringAssert<?> testExceptionMsg(String before) {
9090
try {
91-
formatter.compute(LineEnding.toUnix(before), FormatterStepImpl.SENTINEL);
91+
formatter.compute(LineEnding.toUnix(before), Formatter.NO_FILE_SENTINEL);
9292
throw new SecurityException("Expected exception");
9393
} catch (Throwable e) {
9494
if (e instanceof SecurityException) {

testlib/src/test/java/com/diffplug/spotless/FormatterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void testExceptionWithSentinelNoFileOnDisk() throws Exception {
142142
.exceptionPolicy(exceptionPolicy)
143143
.build();
144144

145-
formatter.compute("someFileContent", FormatterStepImpl.SENTINEL);
145+
formatter.compute("someFileContent", Formatter.NO_FILE_SENTINEL);
146146
}
147147

148148
// rootDir may be a path not from the default FileSystem

0 commit comments

Comments
 (0)