Skip to content

Commit 7afe75b

Browse files
committed
Minor refactor, remove useless extra builder class
1 parent 850b287 commit 7afe75b

File tree

3 files changed

+52
-101
lines changed

3 files changed

+52
-101
lines changed

lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java

Lines changed: 48 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class RomeStep {
5050
* Path to the directory with the {@code rome.json} config file, can be
5151
* <code>null</code>, in which case the defaults are used.
5252
*/
53-
private final String configPath;
53+
private String configPath;
5454

5555
/**
5656
* The language (syntax) of the input files to format. When <code>null</code> or
@@ -68,7 +68,7 @@ public class RomeStep {
6868
* <li>json (JSON)</li>
6969
* </ul>
7070
*/
71-
private final String language;
71+
private String language;
7272

7373
/**
7474
* Path to the Rome executable. Can be <code>null</code>, but either a path to
@@ -106,8 +106,8 @@ public static String name() {
106106
* @param downloadDir Directory where to place the downloaded executable.
107107
* @return A new Rome step that download the executable from the network.
108108
*/
109-
public static RomeStep.Builder withExeDownload(String version, String downloadDir) {
110-
return new RomeStep.Builder(version, null, downloadDir);
109+
public static RomeStep withExeDownload(String version, String downloadDir) {
110+
return new RomeStep(version, null, downloadDir);
111111
}
112112

113113
/**
@@ -117,8 +117,8 @@ public static RomeStep.Builder withExeDownload(String version, String downloadDi
117117
* @param pathToExe Path to the Rome executable to use.
118118
* @return A new Rome step that format with the given executable.
119119
*/
120-
public static RomeStep.Builder withExePath(String pathToExe) {
121-
return new RomeStep.Builder(null, pathToExe, null);
120+
public static RomeStep withExePath(String pathToExe) {
121+
return new RomeStep(null, pathToExe, null);
122122
}
123123

124124
/**
@@ -217,12 +217,10 @@ private static void validateRomeExecutable(String resolvedPathToExe) {
217217
*
218218
* @param builder Builder with the configuration to use.
219219
*/
220-
private RomeStep(RomeStep.Builder builder) {
221-
this.version = builder.version != null && !builder.version.isBlank() ? builder.version : defaultVersion();
222-
this.pathToExe = builder.pathToExe;
223-
this.downloadDir = builder.downloadDir;
224-
this.configPath = builder.configPath;
225-
this.language = builder.language;
220+
private RomeStep(String version, String pathToExe, String downloadDir) {
221+
this.version = version != null && !version.isBlank() ? version : defaultVersion();
222+
this.pathToExe = pathToExe;
223+
this.downloadDir = downloadDir;
226224
}
227225

228226
/**
@@ -235,6 +233,44 @@ public FormatterStep create() {
235233
return FormatterStep.createLazy(name(), this::createState, State::toFunc);
236234
}
237235

236+
/**
237+
* Sets the path to the directory with the {@code rome.json} config file. When
238+
* no config path is set, the default configuration is used.
239+
*
240+
* @param configPath Config path to use. Must point to a directory which contain
241+
* a file named {@code rome.json}.
242+
* @return This builder instance for chaining method calls.
243+
*/
244+
public RomeStep withConfigPath(String configPath) {
245+
this.configPath = configPath;
246+
return this;
247+
}
248+
249+
/**
250+
* Sets the language of the files to format When no language is set, it is
251+
* determined automatically from the file name. The following languages are
252+
* currently supported by Rome.
253+
*
254+
* <ul>
255+
* <li>js (JavaScript)</li>
256+
* <li>jsx (JavaScript + JSX)</li>
257+
* <li>js? (JavaScript or JavaScript + JSX, depending on the file
258+
* extension)</li>
259+
* <li>ts (TypeScript)</li>
260+
* <li>tsx (TypeScript + JSX)</li>
261+
* <li>ts? (TypeScript or TypeScript + JSX, depending on the file
262+
* extension)</li>
263+
* <li>json (JSON)</li>
264+
* </ul>
265+
*
266+
* @param language The language of the files to format.
267+
* @return This builder instance for chaining method calls.
268+
*/
269+
public RomeStep withLanguage(String language) {
270+
this.language = language;
271+
return this;
272+
}
273+
238274
/**
239275
* Resolves the Rome executable, possibly downloading it from the network, and
240276
* creates a new state instance with the resolved executable that can format
@@ -290,88 +326,6 @@ private String resolveExe() throws IOException, InterruptedException {
290326
}
291327
}
292328

293-
public final static class Builder {
294-
/** See {@link RomeStep#configPath} */
295-
private String configPath;
296-
297-
/** See {@link RomeStep#downloadDir} */
298-
private final String downloadDir;
299-
300-
/** See {@link RomeStep#language} */
301-
private String language;
302-
303-
/** See {@link RomeStep#pathToExe} */
304-
private final String pathToExe;
305-
306-
/** See {@link RomeStep#version} */
307-
private final String version;
308-
309-
/**
310-
* Creates a new builder for configuring a Rome step that can format code via
311-
* Rome. Either a version and and downloadDir, or a pathToExe must be given.
312-
*
313-
* @param version The version of Rome to download, see
314-
* {@link RomeStep#version}.
315-
* @param pathToExe The path to the Rome executable to use, see
316-
* {@link RomeStep#pathToExe}.
317-
* @param downloadDir The path to the download directory when downloading Rome
318-
* from the network, {@link RomeStep#downloadDir}.
319-
*/
320-
private Builder(String version, String pathToExe, String downloadDir) {
321-
this.version = version;
322-
this.pathToExe = pathToExe;
323-
this.downloadDir = downloadDir;
324-
}
325-
326-
/**
327-
* Creates a new Rome step for formatting code with Rome from the current
328-
* configuration of this builder.
329-
*
330-
* @return A new Rome step with the current configuration.
331-
*/
332-
public RomeStep build() {
333-
return new RomeStep(this);
334-
}
335-
336-
/**
337-
* Sets the path to the directory with the {@code rome.json} config file. When
338-
* no config path is set, the default configuration is used.
339-
*
340-
* @param configPath Config path to use. Must point to a directory which contain
341-
* a file named {@code rome.json}.
342-
* @return This builder instance for chaining method calls.
343-
*/
344-
public Builder withConfigPath(String configPath) {
345-
this.configPath = configPath;
346-
return this;
347-
}
348-
349-
/**
350-
* Sets the language of the files to format When no language is set, it is
351-
* determined automatically from the file name. The following languages are
352-
* currently supported by Rome.
353-
*
354-
* <ul>
355-
* <li>js (JavaScript)</li>
356-
* <li>jsx (JavaScript + JSX)</li>
357-
* <li>js? (JavaScript or JavaScript + JSX, depending on the file
358-
* extension)</li>
359-
* <li>ts (TypeScript)</li>
360-
* <li>tsx (TypeScript + JSX)</li>
361-
* <li>ts? (TypeScript or TypeScript + JSX, depending on the file
362-
* extension)</li>
363-
* <li>json (JSON)</li>
364-
* </ul>
365-
*
366-
* @param language The language of the files to format.
367-
* @return This builder instance for chaining method calls.
368-
*/
369-
public Builder withLanguage(String language) {
370-
this.language = language;
371-
return this;
372-
}
373-
}
374-
375329
/**
376330
* The internal state used by the Rome formatter. A state instance is created
377331
* when the spotless plugin for Maven or Gradle is executed, and reused for all

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,7 @@ protected FormatterStep createStep() {
770770
builder.withConfigPath(resolvedConfigPath.toString());
771771
}
772772
builder.withLanguage(getLanguage());
773-
var rome = builder.build();
774-
return rome.create();
773+
return builder.create();
775774
}
776775

777776
/**
@@ -842,7 +841,7 @@ private File findDataDir() {
842841
*
843842
* @return A builder for a Rome step.
844843
*/
845-
private RomeStep.Builder newBuilder() {
844+
private RomeStep newBuilder() {
846845
if (pathToExe != null) {
847846
var resolvedPathToExe = resolvePathToExe();
848847
return RomeStep.withExePath(resolvedPathToExe);

plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.diffplug.spotless.maven.FormatterStepConfig;
2424
import com.diffplug.spotless.maven.FormatterStepFactory;
2525
import com.diffplug.spotless.rome.RomeStep;
26-
import com.diffplug.spotless.rome.RomeStep.Builder;
2726

2827
/**
2928
* Factory for creating the Rome formatter step that can format format code in
@@ -94,8 +93,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) {
9493
if (getLanguage() != null) {
9594
builder.withLanguage(getLanguage());
9695
}
97-
var step = builder.build();
98-
return step.create();
96+
return builder.create();
9997
}
10098

10199
/**
@@ -127,7 +125,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) {
127125
* the currently executed project.
128126
* @return A builder for a Rome step.
129127
*/
130-
private Builder newBuilder(FormatterStepConfig config) {
128+
private RomeStep newBuilder(FormatterStepConfig config) {
131129
if (pathToExe != null) {
132130
var resolvedExePath = resolveExePath(config);
133131
return RomeStep.withExePath(resolvedExePath);

0 commit comments

Comments
 (0)