|
15 | 15 | */
|
16 | 16 | package com.diffplug.spotless;
|
17 | 17 |
|
18 |
| -import java.util.Locale; |
19 | 18 | import java.util.Objects;
|
20 |
| -import java.util.Set; |
21 | 19 |
|
22 | 20 | import org.assertj.core.api.Assertions;
|
23 | 21 |
|
24 |
| -class StepHarnessBase<T extends StepHarnessBase<?>> implements AutoCloseable { |
| 22 | +class StepHarnessBase implements AutoCloseable { |
25 | 23 | private final Formatter formatter;
|
26 |
| - private Formatter roundTripped; |
27 |
| - private boolean supportsRoundTrip = false; |
28 | 24 |
|
29 | 25 | protected StepHarnessBase(Formatter formatter) {
|
30 | 26 | this.formatter = Objects.requireNonNull(formatter);
|
31 |
| - if (formatter.getSteps().size() == 1) { |
32 |
| - // our goal is for everything to be roundtrip serializable |
33 |
| - // the steps to get there are |
34 |
| - // - make every individual step round-trippable |
35 |
| - // - make the other machinery (Formatter, LineEnding, etc) round-trippable |
36 |
| - // - done! |
37 |
| - // |
38 |
| - // Right now, we're still trying to get each and every single step to be round-trippable. |
39 |
| - // You can help by add a test below, make sure that the test for that step fails, and then |
40 |
| - // make the test pass. `FormatterStepEqualityOnStateSerialization` is a good base class for |
41 |
| - // easily converting a step to round-trip serialization while maintaining easy and concise |
42 |
| - // equality code. |
43 |
| - String onlyStepName = formatter.getSteps().get(0).getName(); |
44 |
| - if (onlyStepName.startsWith("indentWith")) { |
45 |
| - supportsRoundTrip = true; |
46 |
| - } else if (onlyStepName.equals("diktat")) { |
47 |
| - supportsRoundTrip = true; |
48 |
| - } else if (onlyStepName.toLowerCase(Locale.ROOT).contains("eclipse")) { |
49 |
| - supportsRoundTrip = true; |
50 |
| - } else if (onlyStepName.equals("fence")) { |
51 |
| - supportsRoundTrip = true; |
52 |
| - } else if (Set.of("black", "buf", "clang", "ktlint", "ktfmt", "scalafmt", "palantir-java-format", "google-java-format", |
53 |
| - "removeUnusedImports", "cleanthat", "No line break between type annotation and type", "antlr4Formatter", |
54 |
| - "gson", "jacksonJson", "apply-json-patch", "jsonSimple", "sortPom", "jacksonYaml", "gherkinUtils", |
55 |
| - "flexmark-java", "freshmark", |
56 |
| - "importOrder", "Remove unnecessary semicolons").contains(onlyStepName)) { |
57 |
| - supportsRoundTrip = true; |
58 |
| - } |
59 |
| - } |
| 27 | + Formatter roundTripped = SerializableEqualityTester.reserialize(formatter); |
| 28 | + Assertions.assertThat(roundTripped).isEqualTo(formatter); |
60 | 29 | }
|
61 | 30 |
|
62 | 31 | protected Formatter formatter() {
|
63 |
| - if (!supportsRoundTrip) { |
64 |
| - return formatter; |
65 |
| - } else { |
66 |
| - if (roundTripped == null) { |
67 |
| - roundTripped = SerializableEqualityTester.reserialize(formatter); |
68 |
| - Assertions.assertThat(roundTripped).isEqualTo(formatter); |
69 |
| - } |
70 |
| - return roundTripped; |
71 |
| - } |
| 32 | + return formatter; |
72 | 33 | }
|
73 | 34 |
|
74 | 35 | @Override
|
75 | 36 | public void close() {
|
76 | 37 | formatter.close();
|
77 |
| - if (roundTripped != null) { |
78 |
| - roundTripped.close(); |
79 |
| - } |
80 | 38 | }
|
81 | 39 | }
|
0 commit comments