Skip to content

Commit fb4b0ff

Browse files
committed
Make Jsr223Step round-trippable
1 parent a704a68 commit fb4b0ff

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

lib/src/main/java/com/diffplug/spotless/generic/Jsr223Step.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-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.
@@ -19,35 +19,52 @@
1919
import java.util.Objects;
2020
import java.util.stream.Collectors;
2121

22+
import javax.annotation.Nullable;
2223
import javax.script.ScriptEngine;
2324
import javax.script.ScriptEngineManager;
2425

2526
import com.diffplug.spotless.FormatterFunc;
2627
import com.diffplug.spotless.FormatterStep;
2728
import com.diffplug.spotless.JarState;
2829
import com.diffplug.spotless.Provisioner;
30+
import com.diffplug.spotless.RoundedStep;
2931

30-
public final class Jsr223Step {
31-
// prevent direct instantiation
32-
private Jsr223Step() {}
32+
public final class Jsr223Step implements RoundedStep {
33+
private static final long serialVersionUID = 1L;
34+
@Nullable
35+
private final JarState.Promised jarState;
36+
private final String engine;
37+
private final String script;
3338

34-
public static FormatterStep create(String name, String dependency, CharSequence engine, CharSequence script, Provisioner provisioner) {
39+
private Jsr223Step(@Nullable JarState.Promised jarState, String engine, String script) {
40+
this.jarState = jarState;
41+
this.engine = engine;
42+
this.script = script;
43+
}
44+
45+
public static FormatterStep create(String name, @Nullable String dependency, CharSequence engine, CharSequence script, Provisioner provisioner) {
3546
Objects.requireNonNull(name, "name");
3647
Objects.requireNonNull(engine, "engine");
3748
Objects.requireNonNull(script, "script");
38-
return FormatterStep.createLazy(name,
39-
() -> new State(dependency == null ? null : JarState.from(dependency, provisioner), engine, script),
49+
return FormatterStep.create(name,
50+
new Jsr223Step(dependency == null ? null : JarState.promise(() -> JarState.from(dependency, provisioner)), engine.toString(), script.toString()),
51+
Jsr223Step::equalityState,
4052
State::toFormatter);
4153
}
4254

55+
private State equalityState() {
56+
return new State(jarState == null ? null : jarState.get(), engine, script);
57+
}
58+
4359
private static final class State implements Serializable {
4460
private static final long serialVersionUID = 1L;
4561

62+
@Nullable
4663
private final JarState jarState;
4764
private final String engine;
4865
private final String script;
4966

50-
State(JarState jarState, CharSequence engine, CharSequence script) {
67+
State(@Nullable JarState jarState, CharSequence engine, CharSequence script) {
5168
this.jarState = jarState;
5269
this.engine = engine.toString();
5370
this.script = script.toString();

0 commit comments

Comments
 (0)