Skip to content

Commit

Permalink
Rename the sentinel and move it to Formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Jan 26, 2023
1 parent 7f7cc49 commit 07a57ff
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lib/src/main/java/com/diffplug/spotless/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public String compute(String unix, File file) {
unix = LineEnding.toUnix(formatted);
}
} catch (Throwable e) {
if (file == FormatterStepImpl.SENTINEL) {
if (file == NO_FILE_SENTINEL) {
exceptionPolicy.handleError(e, step, "");
} else {
// Path may be forged from a different FileSystem than Filesystem.default
Expand Down Expand Up @@ -289,4 +289,7 @@ public void close() {
}
}
}

/** This Sentinel reference may be used to Formatter requires a File, while there is no actual File to format */
public static final File NO_FILE_SENTINEL = new File("NO_FILE_SENTINEL");
}
6 changes: 3 additions & 3 deletions lib/src/main/java/com/diffplug/spotless/FormatterFunc.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -127,7 +127,7 @@ public String apply(String unix, File file) throws Exception {

@Override
public String apply(String unix) throws Exception {
return apply(unix, FormatterStepImpl.SENTINEL);
return apply(unix, Formatter.NO_FILE_SENTINEL);
}
};
}
Expand Down Expand Up @@ -156,7 +156,7 @@ default String apply(String unix, File file) throws Exception {

@Override
default String apply(String unix) throws Exception {
return apply(unix, FormatterStepImpl.SENTINEL);
return apply(unix, Formatter.NO_FILE_SENTINEL);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti
}
}

/**This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format */
public static final File SENTINEL = new File("");

static void checkNotSentinel(File file) {
if (file == SENTINEL) {
if (file == Formatter.NO_FILE_SENTINEL) {
throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public AbstractStringAssert<?> testResourceExceptionMsg(String resourceBefore) {

public AbstractStringAssert<?> testExceptionMsg(String before) {
try {
formatter.compute(LineEnding.toUnix(before), FormatterStepImpl.SENTINEL);
formatter.compute(LineEnding.toUnix(before), Formatter.NO_FILE_SENTINEL);
throw new SecurityException("Expected exception");
} catch (Throwable e) {
if (e instanceof SecurityException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void testExceptionWithSentinelNoFileOnDisk() throws Exception {
.exceptionPolicy(exceptionPolicy)
.build();

formatter.compute("someFileContent", FormatterStepImpl.SENTINEL);
formatter.compute("someFileContent", Formatter.NO_FILE_SENTINEL);
}

// rootDir may be a path not from the default FileSystem
Expand Down

0 comments on commit 07a57ff

Please sign in to comment.