From 491cad5d0943b98d0b4f83af8d2abf40d01bdf83 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 19 Nov 2023 18:22:11 +0800 Subject: [PATCH] Clean up BaseKotlinExtension --- .../gradle/spotless/BaseKotlinExtension.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java index 5ced54a94e..13a75ed6e9 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -70,11 +70,10 @@ public KtfmtConfig ktfmt(String version) { protected abstract boolean isScript(); public class DiktatConfig { - private final String version; private FileSignature config; - DiktatConfig(String version) { + private DiktatConfig(String version) { Objects.requireNonNull(version, "version"); this.version = version; addStep(createStep()); @@ -97,24 +96,18 @@ private FormatterStep createStep() { } public class KtfmtConfig { - final String version; - KtfmtStep.Style style; - KtfmtStep.KtfmtFormattingOptions options; + private final String version; + private KtfmtStep.Style style; + private KtfmtStep.KtfmtFormattingOptions options; private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); - KtfmtConfig(String version) { + private KtfmtConfig(String version) { Objects.requireNonNull(version); this.version = Objects.requireNonNull(version); addStep(createStep()); } - private ConfigurableStyle style(KtfmtStep.Style style) { - this.style = style; - replaceStep(createStep()); - return configurableStyle; - } - public ConfigurableStyle dropboxStyle() { return style(KtfmtStep.Style.DROPBOX); } @@ -131,13 +124,18 @@ public void configure(Consumer optionsConfigur this.configurableStyle.configure(optionsConfiguration); } + private ConfigurableStyle style(KtfmtStep.Style style) { + this.style = style; + replaceStep(createStep()); + return configurableStyle; + } + private FormatterStep createStep() { return KtfmtStep.create(version, provisioner(), style, options); } public class ConfigurableStyle { - - public void configure(Consumer optionsConfiguration) { + private void configure(Consumer optionsConfiguration) { KtfmtStep.KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtStep.KtfmtFormattingOptions(); optionsConfiguration.accept(ktfmtFormattingOptions); options = ktfmtFormattingOptions; @@ -147,26 +145,27 @@ public void configure(Consumer optionsConfigur } public class KtlintConfig { - private final String version; @Nullable private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KtlintConfig(String version, Map config, + private KtlintConfig( + String version, + Map userData, Map editorConfigOverride) throws IOException { Objects.requireNonNull(version); File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; this.version = version; this.editorConfigPath = editorConfigPath; - this.userData = config; + this.userData = userData; this.editorConfigOverride = editorConfigOverride; addStep(createStep()); } - public KtlintConfig setEditorConfigPath(Object editorConfigPath) throws IOException { + public KtlintConfig setEditorConfigPath(@Nullable Object editorConfigPath) throws IOException { if (editorConfigPath == null) { this.editorConfigPath = null; } else {