Skip to content

Commit 1a3df00

Browse files
committed
Fix spotbugs
1 parent 6c0d270 commit 1a3df00

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,31 @@ private static final class State implements Serializable {
158158
this.includeDraft = includeDraft;
159159
}
160160

161+
private static class JvmSupportFormatterFunc implements FormatterFunc {
162+
163+
final Object formatter;
164+
final Method formatterMethod;
165+
166+
private JvmSupportFormatterFunc(Object formatter, Method formatterMethod) {
167+
this.formatter = formatter;
168+
this.formatterMethod = formatterMethod;
169+
}
170+
171+
@Override
172+
public String apply(String input) throws Exception {
173+
return apply(input, Formatter.NO_FILE_SENTINEL);
174+
}
175+
176+
@Override
177+
public String apply(String input, File file) throws Exception {
178+
if (file.isAbsolute()) {
179+
// Cleanthat expects a relative file as input (relative to the root of the repository)
180+
file = new File(".", file.getPath());
181+
}
182+
return (String) formatterMethod.invoke(formatter, input, file);
183+
}
184+
}
185+
161186
FormatterFunc createFormat() {
162187
ClassLoader classLoader = jarState.getClassLoader();
163188

@@ -173,21 +198,7 @@ FormatterFunc createFormat() {
173198
throw new IllegalStateException("Issue executing the formatter", e);
174199
}
175200

176-
FormatterFunc formatterFunc = new FormatterFunc() {
177-
@Override
178-
public String apply(String input) throws Exception {
179-
return apply(input, Formatter.NO_FILE_SENTINEL);
180-
}
181-
182-
@Override
183-
public String apply(String input, File file) throws Exception {
184-
if (file.isAbsolute()) {
185-
// Cleanthat expects a relative file as input (relative to the root of the repository)
186-
file = new File(".", file.getPath());
187-
}
188-
return (String) formatterMethod.invoke(formatter, input, file);
189-
}
190-
};
201+
FormatterFunc formatterFunc = new JvmSupportFormatterFunc(formatter, formatterMethod);
191202

192203
return JVM_SUPPORT.suggestLaterVersionOnError(version, formatterFunc);
193204
}

0 commit comments

Comments
 (0)