Skip to content

Commit 39d1653

Browse files
committed
refactor: move idea to generic formatters
as it can handle various file formats besides java.
1 parent c067d28 commit 39d1653

File tree

11 files changed

+58
-57
lines changed

11 files changed

+58
-57
lines changed

lib/src/main/java/com/diffplug/spotless/java/IdeaStep.java renamed to lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 DiffPlug
2+
* Copyright 2024-2025 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.
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.java;
16+
package com.diffplug.spotless.generic;
1717

1818
import java.io.File;
1919
import java.io.IOException;

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep;
6666
import com.diffplug.spotless.generic.EndWithNewlineStep;
6767
import com.diffplug.spotless.generic.FenceStep;
68+
import com.diffplug.spotless.generic.IdeaStep;
6869
import com.diffplug.spotless.generic.IndentStep;
6970
import com.diffplug.spotless.generic.LicenseHeaderStep;
7071
import com.diffplug.spotless.generic.LicenseHeaderStep.YearMode;
@@ -960,6 +961,45 @@ public EclipseWtpConfig eclipseWtp(EclipseWtpFormatterStep type, String version)
960961
return new EclipseWtpConfig(type, version);
961962
}
962963

964+
public IdeaConfig idea() {
965+
return new IdeaConfig();
966+
}
967+
968+
public class IdeaConfig {
969+
private String binaryPath;
970+
private String configPath;
971+
private boolean withDefaults = false;
972+
973+
IdeaConfig() {
974+
addStep(createStep());
975+
}
976+
977+
private FormatterStep createStep() {
978+
return IdeaStep.create(withDefaults, binaryPath, configPath);
979+
}
980+
981+
public IdeaConfig binaryPath(String binaryPath) {
982+
requireNonNull(binaryPath);
983+
this.binaryPath = binaryPath;
984+
replaceStep(createStep());
985+
return this;
986+
}
987+
988+
public IdeaConfig configPath(String configPath) {
989+
requireNonNull(configPath);
990+
this.configPath = configPath;
991+
replaceStep(createStep());
992+
return this;
993+
}
994+
995+
public IdeaConfig withDefaults(Boolean withDefaults) {
996+
requireNonNull(withDefaults);
997+
this.withDefaults = withDefaults;
998+
replaceStep(createStep());
999+
return this;
1000+
}
1001+
}
1002+
9631003
/**
9641004
* <pre>
9651005
* spotless {

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.diffplug.spotless.java.CleanthatJavaStep;
3939
import com.diffplug.spotless.java.FormatAnnotationsStep;
4040
import com.diffplug.spotless.java.GoogleJavaFormatStep;
41-
import com.diffplug.spotless.java.IdeaStep;
4241
import com.diffplug.spotless.java.ImportOrderStep;
4342
import com.diffplug.spotless.java.PalantirJavaFormatStep;
4443
import com.diffplug.spotless.java.RemoveUnusedImportsStep;
@@ -358,45 +357,6 @@ public EclipseConfig withP2Mirrors(Map<String, String> mirrors) {
358357

359358
}
360359

361-
public IdeaConfig idea() {
362-
return new IdeaConfig();
363-
}
364-
365-
public class IdeaConfig {
366-
private String binaryPath;
367-
private String configPath;
368-
private boolean withDefaults = false;
369-
370-
IdeaConfig() {
371-
addStep(createStep());
372-
}
373-
374-
private FormatterStep createStep() {
375-
return IdeaStep.create(withDefaults, binaryPath, configPath);
376-
}
377-
378-
public IdeaConfig binaryPath(String binaryPath) {
379-
Objects.requireNonNull(binaryPath);
380-
this.binaryPath = binaryPath;
381-
replaceStep(createStep());
382-
return this;
383-
}
384-
385-
public IdeaConfig configPath(String configPath) {
386-
Objects.requireNonNull(configPath);
387-
this.configPath = configPath;
388-
replaceStep(createStep());
389-
return this;
390-
}
391-
392-
public IdeaConfig withDefaults(Boolean withDefaults) {
393-
Objects.requireNonNull(withDefaults);
394-
this.withDefaults = withDefaults;
395-
replaceStep(createStep());
396-
return this;
397-
}
398-
}
399-
400360
/** Removes newlines between type annotations and types. */
401361
public FormatAnnotationsConfig formatAnnotations() {
402362
return new FormatAnnotationsConfig();

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaIdeaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 DiffPlug
2+
* Copyright 2020-2025 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.

plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 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.
@@ -38,6 +38,7 @@
3838
import com.diffplug.spotless.LineEnding;
3939
import com.diffplug.spotless.maven.generic.EclipseWtp;
4040
import com.diffplug.spotless.maven.generic.EndWithNewline;
41+
import com.diffplug.spotless.maven.generic.Idea;
4142
import com.diffplug.spotless.maven.generic.Indent;
4243
import com.diffplug.spotless.maven.generic.Jsr223;
4344
import com.diffplug.spotless.maven.generic.LicenseHeader;
@@ -147,6 +148,10 @@ public final void addPrettier(Prettier prettier) {
147148
addStepFactory(prettier);
148149
}
149150

151+
public final void addIdea(Idea idea) {
152+
addStepFactory(idea);
153+
}
154+
150155
public final void addToggleOffOn(ToggleOffOn toggle) {
151156
this.toggle = toggle;
152157
}

plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Idea.java renamed to plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Idea.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 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.
@@ -13,12 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.maven.java;
16+
package com.diffplug.spotless.maven.generic;
1717

1818
import org.apache.maven.plugins.annotations.Parameter;
1919

2020
import com.diffplug.spotless.FormatterStep;
21-
import com.diffplug.spotless.java.IdeaStep;
21+
import com.diffplug.spotless.generic.IdeaStep;
2222
import com.diffplug.spotless.maven.FormatterStepConfig;
2323
import com.diffplug.spotless.maven.FormatterStepFactory;
2424

plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ public void addImportOrder(ImportOrder importOrder) {
6868
addStepFactory(importOrder);
6969
}
7070

71-
public void addIdea(Idea idea) {
72-
addStepFactory(idea);
73-
}
74-
7571
public void addPalantirJavaFormat(PalantirJavaFormat palantirJavaFormat) {
7672
addStepFactory(palantirJavaFormat);
7773
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/java/IdeaTest.java renamed to plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/IdeaTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 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.
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.maven.java;
16+
package com.diffplug.spotless.maven.generic;
1717

1818
import org.junit.jupiter.api.Test;
1919

testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 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.

testlib/src/main/java/com/diffplug/spotless/tag/IdeaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 DiffPlug
2+
* Copyright 2021-2025 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.

0 commit comments

Comments
 (0)