Skip to content

Commit

Permalink
Fix spotbugs warnings in FenceStep.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Jan 3, 2023
1 parent 2991b26 commit 01f73c0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/generic/FenceStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -94,6 +96,8 @@ public FormatterStep applyWithin(List<FormatterStep> steps) {
}

static class ApplyWithin extends Apply implements FormatterFunc.Closeable.ResourceFuncNeedsFile<Formatter> {
private static final long serialVersionUID = 17061466531957339L;

ApplyWithin(Pattern regex, List<FormatterStep> steps) {
super(regex, steps);
}
Expand All @@ -112,6 +116,8 @@ public String apply(Formatter formatter, String unix, File file) throws Exceptio
}

static class PreserveWithin extends Apply implements FormatterFunc.Closeable.ResourceFuncNeedsFile<Formatter> {
private static final long serialVersionUID = -8676786492305178343L;

PreserveWithin(Pattern regex, List<FormatterStep> steps) {
super(regex, steps);
}
Expand All @@ -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<FormatterStep> steps;

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 01f73c0

Please sign in to comment.