From 01f73c092a3fa7a49615f79562f7a22e88a18c40 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 Jan 2023 16:24:06 -0800 Subject: [PATCH] Fix spotbugs warnings in FenceStep. --- .../com/diffplug/spotless/generic/FenceStep.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/FenceStep.java b/lib/src/main/java/com/diffplug/spotless/generic/FenceStep.java index 179ba7746f..33a9adb6db 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/FenceStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/FenceStep.java @@ -29,6 +29,8 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.LineEnding; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class FenceStep { /** Declares the name of the step. */ public static FenceStep named(String name) { @@ -94,6 +96,8 @@ public FormatterStep applyWithin(List steps) { } static class ApplyWithin extends Apply implements FormatterFunc.Closeable.ResourceFuncNeedsFile { + private static final long serialVersionUID = 17061466531957339L; + ApplyWithin(Pattern regex, List steps) { super(regex, steps); } @@ -112,6 +116,8 @@ public String apply(Formatter formatter, String unix, File file) throws Exceptio } static class PreserveWithin extends Apply implements FormatterFunc.Closeable.ResourceFuncNeedsFile { + private static final long serialVersionUID = -8676786492305178343L; + PreserveWithin(Pattern regex, List steps) { super(regex, steps); } @@ -133,7 +139,9 @@ public String apply(Formatter formatter, String unix, File file) throws Exceptio } } + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") static class Apply implements Serializable { + private static final long serialVersionUID = -2301848328356559915L; final Pattern regex; final List steps; @@ -189,8 +197,9 @@ protected String assembleGroups(String unix) { builder.append(unix, lastEnd, unix.length()); return builder.toString(); } else { - int startLine = 1 + (int) builder.toString().codePoints().filter(c -> c == '\n').count(); - int endLine = 1 + (int) unix.codePoints().filter(c -> c == '\n').count(); + // these will be needed to generate Lints later on + // int startLine = 1 + (int) builder.toString().codePoints().filter(c -> c == '\n').count(); + // int endLine = 1 + (int) unix.codePoints().filter(c -> c == '\n').count(); // throw an error with either the full regex, or the nicer open/close pair Matcher openClose = Pattern.compile("\\\\Q([\\s\\S]*?)\\\\E" + "\\Q([\\s\\S]*?)\\E" + "\\\\Q([\\s\\S]*?)\\\\E")