1
1
/*
2
- * Copyright 2020-2022 DiffPlug
2
+ * Copyright 2020-2023 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -64,10 +64,10 @@ public ClangFormatStep withPathToExe(String pathToExe) {
64
64
}
65
65
66
66
public FormatterStep create () {
67
- return FormatterStep .createLazy (name (), this ::createState , State ::toFunc );
67
+ return FormatterStep .createLazy (name (), this ::createState , RoundtripState :: state , State ::toFunc );
68
68
}
69
69
70
- private State createState () throws IOException , InterruptedException {
70
+ private RoundtripState createState () throws IOException , InterruptedException {
71
71
String howToInstall = "" +
72
72
"You can download clang-format from https://releases.llvm.org and " +
73
73
"then point Spotless to it with {@code pathToExe('/path/to/clang-format')} " +
@@ -82,7 +82,25 @@ private State createState() throws IOException, InterruptedException {
82
82
.fixWrongVersion (
83
83
"You can tell Spotless to use the version you already have with {@code clangFormat('{versionFound}')}" +
84
84
"or you can download the currently specified version, {version}.\n " + howToInstall );
85
- return new State (this , exe );
85
+ return new RoundtripState (this , exe );
86
+ }
87
+
88
+ static class RoundtripState implements Serializable {
89
+ private static final long serialVersionUID = 1L ;
90
+
91
+ final String version ;
92
+ final @ Nullable String style ;
93
+ final ForeignExe exe ;
94
+
95
+ RoundtripState (ClangFormatStep step , ForeignExe exe ) {
96
+ this .version = step .version ;
97
+ this .style = step .style ;
98
+ this .exe = exe ;
99
+ }
100
+
101
+ private State state () {
102
+ return new State (version , style , exe );
103
+ }
86
104
}
87
105
88
106
@ SuppressFBWarnings ("SE_TRANSIENT_FIELD_NOT_RESTORED" )
@@ -95,9 +113,9 @@ static class State implements Serializable {
95
113
// used for executing
96
114
private transient @ Nullable List <String > args ;
97
115
98
- State (ClangFormatStep step , ForeignExe pathToExe ) {
99
- this .version = step . version ;
100
- this .style = step . style ;
116
+ State (String version , @ Nullable String style , ForeignExe pathToExe ) {
117
+ this .version = version ;
118
+ this .style = style ;
101
119
this .exe = Objects .requireNonNull (pathToExe );
102
120
}
103
121
0 commit comments