Skip to content

Commit f5e3dd3

Browse files
committed
Make ImportOrderStep round-trippable
1 parent 931e106 commit f5e3dd3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 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.
@@ -34,12 +34,16 @@
3434
import java.util.stream.Collectors;
3535
import java.util.stream.Stream;
3636

37+
import javax.annotation.Nullable;
38+
3739
import com.diffplug.spotless.FormatterFunc;
3840
import com.diffplug.spotless.FormatterStep;
41+
import com.diffplug.spotless.RoundedStep;
3942

4043
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4144

42-
public final class ImportOrderStep {
45+
public final class ImportOrderStep implements RoundedStep {
46+
private static final long serialVersionUID = 1L;
4347
private static final boolean WILDCARDS_LAST_DEFAULT = false;
4448
private static final boolean SEMANTIC_SORT_DEFAULT = false;
4549
private static final Set<String> TREAT_AS_PACKAGE_DEFAULT = Set.of();
@@ -84,9 +88,8 @@ public FormatterStep createFrom(boolean wildcardsLast, boolean semanticSort, Set
8488

8589
private FormatterStep createFrom(boolean wildcardsLast, boolean semanticSort, Set<String> treatAsPackage,
8690
Set<String> treatAsClass, Supplier<List<String>> importOrder) {
87-
return FormatterStep.createLazy("importOrder",
88-
() -> new State(importOrder.get(), lineFormat, wildcardsLast, semanticSort, treatAsPackage,
89-
treatAsClass),
91+
return FormatterStep.create("importOrder",
92+
new State(importOrder.get(), lineFormat, wildcardsLast, semanticSort, treatAsPackage, treatAsClass),
9093
State::toFormatter);
9194
}
9295

@@ -121,8 +124,12 @@ private static final class State implements Serializable {
121124
private final TreeSet<String> treatAsPackage;
122125
private final TreeSet<String> treatAsClass;
123126

124-
State(List<String> importOrder, String lineFormat, boolean wildcardsLast, boolean semanticSort,
125-
Set<String> treatAsPackage, Set<String> treatAsClass) {
127+
State(List<String> importOrder,
128+
String lineFormat,
129+
boolean wildcardsLast,
130+
boolean semanticSort,
131+
@Nullable Set<String> treatAsPackage,
132+
@Nullable Set<String> treatAsClass) {
126133
this.importOrder = importOrder;
127134
this.lineFormat = lineFormat;
128135
this.wildcardsLast = wildcardsLast;

0 commit comments

Comments
 (0)