Skip to content

Commit 2046daf

Browse files
committed
Looks like spotbugs is stricter now that we're on Java 11.
1 parent 0ba186e commit 2046daf

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java

Lines changed: 17 additions & 14 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.
@@ -143,18 +143,14 @@ public String getMessage() {
143143
Objects.requireNonNull(runToFix, "runToFix");
144144
Objects.requireNonNull(formatter, "formatter");
145145
Objects.requireNonNull(problemFiles, "problemFiles");
146-
DiffMessageFormatter diffFormater = new DiffMessageFormatter(this);
146+
DiffMessageFormatter diffFormater = new DiffMessageFormatter(formatter, problemFiles);
147147
return "The following files had format violations:\n"
148148
+ diffFormater.buffer
149149
+ runToFix;
150150
} catch (IOException e) {
151151
throw Errors.asRuntime(e);
152152
}
153153
}
154-
155-
String relativePath(File file) {
156-
return formatter.getRootDir().relativize(file.toPath()).toString();
157-
}
158154
}
159155

160156
private static final int MAX_CHECK_MESSAGE_LINES = 50;
@@ -163,25 +159,32 @@ String relativePath(File file) {
163159
private final StringBuilder buffer = new StringBuilder(MAX_CHECK_MESSAGE_LINES * 64);
164160
private int numLines = 0;
165161

166-
private DiffMessageFormatter(Builder builder) throws IOException {
167-
ListIterator<File> problemIter = builder.problemFiles.listIterator();
162+
private final CleanProvider formatter;
163+
164+
private DiffMessageFormatter(CleanProvider formatter, List<File> problemFiles) throws IOException {
165+
this.formatter = Objects.requireNonNull(formatter, "formatter");
166+
ListIterator<File> problemIter = problemFiles.listIterator();
168167
while (problemIter.hasNext() && numLines < MAX_CHECK_MESSAGE_LINES) {
169168
File file = problemIter.next();
170-
addFile(builder.relativePath(file) + "\n" + DiffMessageFormatter.diff(builder, file));
169+
addFile(relativePath(file) + "\n" + diff(file));
171170
}
172171
if (problemIter.hasNext()) {
173-
int remainingFiles = builder.problemFiles.size() - problemIter.nextIndex();
172+
int remainingFiles = problemFiles.size() - problemIter.nextIndex();
174173
if (remainingFiles >= MAX_FILES_TO_LIST) {
175174
buffer.append("Violations also present in ").append(remainingFiles).append(" other files.\n");
176175
} else {
177176
buffer.append("Violations also present in:\n");
178177
while (problemIter.hasNext()) {
179-
addIntendedLine(NORMAL_INDENT, builder.relativePath(problemIter.next()));
178+
addIntendedLine(NORMAL_INDENT, relativePath(problemIter.next()));
180179
}
181180
}
182181
}
183182
}
184183

184+
private String relativePath(File file) {
185+
return formatter.getRootDir().relativize(file.toPath()).toString();
186+
}
187+
185188
private static final int MIN_LINES_PER_FILE = 4;
186189
private static final Splitter NEWLINE_SPLITTER = Splitter.on('\n');
187190

@@ -230,10 +233,10 @@ private void addIntendedLine(String indent, String line) {
230233
* look like if formatted using the given formatter. Does not end with any newline
231234
* sequence (\n, \r, \r\n).
232235
*/
233-
private static String diff(Builder builder, File file) throws IOException {
234-
String raw = new String(Files.readAllBytes(file.toPath()), builder.formatter.getEncoding());
236+
private String diff(File file) throws IOException {
237+
String raw = new String(Files.readAllBytes(file.toPath()), formatter.getEncoding());
235238
String rawUnix = LineEnding.toUnix(raw);
236-
String formatted = builder.formatter.getFormatted(file, rawUnix);
239+
String formatted = formatter.getFormatted(file, rawUnix);
237240
String formattedUnix = LineEnding.toUnix(formatted);
238241

239242
if (rawUnix.equals(formattedUnix)) {

0 commit comments

Comments
 (0)