Skip to content

Commit 11147a9

Browse files
committed
Change to using the EclipseWtpFormatterStep enum as the argument.
1 parent 6369881 commit 11147a9

File tree

3 files changed

+7
-33
lines changed

3 files changed

+7
-33
lines changed

lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java

-19
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@
1515
*/
1616
package com.diffplug.spotless.extra.wtp;
1717

18-
import static java.util.Arrays.stream;
19-
import static java.util.stream.Collectors.joining;
20-
2118
import java.io.File;
2219
import java.lang.reflect.InvocationTargetException;
2320
import java.lang.reflect.Method;
24-
import java.util.Locale;
25-
import java.util.Objects;
2621
import java.util.Properties;
2722

2823
import com.diffplug.spotless.FormatterFunc;
@@ -53,20 +48,6 @@ public enum EclipseWtpFormatterStep {
5348
this.formatterCall = formatterCall;
5449
}
5550

56-
/** Similar to {@link #valueOf(Class, String)}, ignores whitespace, case and adds helpful exception messages. */
57-
public static EclipseWtpFormatterStep valueFrom(String name) {
58-
Objects.requireNonNull(name);
59-
name = name.trim().toUpperCase(Locale.ENGLISH);
60-
try {
61-
return valueOf(name);
62-
} catch (IllegalArgumentException e) {
63-
throw new IllegalArgumentException(e.getMessage() +
64-
" (allowed values: " +
65-
stream(values()).map(enumType -> enumType.toString()).collect(joining("; ")) +
66-
")");
67-
}
68-
}
69-
7051
public EclipseBasedStepBuilder createBuilder(Provisioner provisioner) {
7152
return new EclipseBasedStepBuilder(NAME, " - " + toString(), provisioner, state -> formatterCall.apply(implementationClassName, state));
7253
}

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

+5-12
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,9 @@ public PrettierConfig prettier() {
488488
public class EclipseWtpConfig {
489489
private final EclipseBasedStepBuilder builder;
490490

491-
EclipseWtpConfig(EclipseWtpFormatterStep type) {
492-
this(type, EclipseWtpFormatterStep.defaultVersion());
493-
}
494-
495491
EclipseWtpConfig(EclipseWtpFormatterStep type, String version) {
496492
builder = type.createBuilder(GradleProvisioner.fromProject(getProject()));
497-
builder.setVersion(EclipseWtpFormatterStep.defaultVersion());
493+
builder.setVersion(version);
498494
addStep(builder.build());
499495
}
500496

@@ -504,17 +500,14 @@ public void configFile(Object... configFiles) {
504500
builder.setPreferences(project.files(configFiles).getFiles());
505501
replaceStep(builder.build());
506502
}
507-
508503
}
509504

510-
public EclipseWtpConfig eclipseWtp(String type) {
511-
return new EclipseWtpConfig(EclipseWtpFormatterStep.valueFrom(type));
505+
public EclipseWtpConfig eclipseWtp(EclipseWtpFormatterStep type) {
506+
return eclipseWtp(type, EclipseWtpFormatterStep.defaultVersion());
512507
}
513508

514-
public EclipseWtpConfig eclipseWtp(String type, String version) {
515-
return new EclipseWtpConfig(
516-
EclipseWtpFormatterStep.valueFrom(type),
517-
version);
509+
public EclipseWtpConfig eclipseWtp(EclipseWtpFormatterStep type, String version) {
510+
return new EclipseWtpConfig(type, version);
518511
}
519512

520513
/** Sets up a format task according to the values in this extension. */

plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
public class EclipseWtp implements FormatterStepFactory {
3030
@Parameter
31-
private String type;
31+
private EclipseWtpFormatterStep type;
3232

3333
@Parameter
3434
private String version;
@@ -38,7 +38,7 @@ public class EclipseWtp implements FormatterStepFactory {
3838

3939
@Override
4040
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
41-
EclipseBasedStepBuilder eclipseConfig = EclipseWtpFormatterStep.valueFrom(type).createBuilder(stepConfig.getProvisioner());
41+
EclipseBasedStepBuilder eclipseConfig = type.createBuilder(stepConfig.getProvisioner());
4242
eclipseConfig.setVersion(version == null ? EclipseWtpFormatterStep.defaultVersion() : version);
4343
if (null != files) {
4444
eclipseConfig.setPreferences(

0 commit comments

Comments
 (0)