Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/src/main/java/com/diffplug/spotless/PaddedCell.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -105,12 +105,12 @@ private static PaddedCell check(Formatter formatter, File file, String original,
}
String appliedOnce = formatter.computeWithLint(original, file, exceptionPerStep);
if (appliedOnce.equals(original)) {
return Type.CONVERGE.create(file, Collections.singletonList(appliedOnce));
return Type.CONVERGE.create(file, List.of(appliedOnce));
}

String appliedTwice = formatter.computeWithLint(appliedOnce, file, exceptionPerStep);
if (appliedOnce.equals(appliedTwice)) {
return Type.CONVERGE.create(file, Collections.singletonList(appliedOnce));
return Type.CONVERGE.create(file, List.of(appliedOnce));
}

List<String> appliedN = new ArrayList<>();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -299,7 +299,7 @@ private State createState() throws IOException, InterruptedException {
validateBiomeExecutable(resolvedPathToExe);
validateBiomeConfigPath(configPath, version);
logger.debug("Using Biome executable located at '{}'", resolvedPathToExe);
var exeSignature = FileSignature.signAsList(Collections.singleton(new File(resolvedPathToExe)));
var exeSignature = FileSignature.signAsList(Set.of(new File(resolvedPathToExe)));
makeExecutable(resolvedPathToExe);
return new State(resolvedPathToExe, exeSignature, configPath, language);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -65,7 +64,7 @@ public static Map<String, String> defaultDevDependencies() {
}

public static Map<String, String> defaultDevDependenciesWithEslint(String version) {
return Collections.singletonMap("eslint", version);
return Map.of("eslint", version);
}

public static FormatterStep create(Map<String, String> devDependencies, Provisioner provisioner, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) {
Expand Down
5 changes: 2 additions & 3 deletions lib/src/main/java/com/diffplug/spotless/npm/JsonWriter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -45,7 +44,7 @@ JsonWriter putAll(Map<String, ?> values) {
}

JsonWriter put(String name, Object value) {
verifyValues(Collections.singletonMap(name, value));
verifyValues(Map.of(name, value));
this.valueMap.put(name, value);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.Serial;
import java.io.Serializable;
import java.time.Duration;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -164,7 +163,7 @@ protected static String replaceDevDependencies(String template, Map<String, Stri
builder.append(",\n");
}
}
return replacePlaceholders(template, Collections.singletonMap("devDependencies", builder.toString()));
return replacePlaceholders(template, Map.of("devDependencies", builder.toString()));
}

private static String replacePlaceholders(String template, Map<String, String> replacements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

Expand Down Expand Up @@ -48,7 +47,7 @@ public static Map<String, String> defaultDevDependencies() {
}

public static Map<String, String> defaultDevDependenciesWithPrettier(String version) {
return Collections.singletonMap("prettier", version);
return Map.of("prettier", version);
}

public static FormatterStep create(Map<String, String> devDependencies, Provisioner provisioner, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.Set;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -87,7 +88,7 @@ private static final class State implements Serializable {

State(JarState jarState, @Nullable File configFile) throws IOException {
this.jarState = jarState;
this.configSignature = FileSignature.signAsList(configFile == null ? Collections.emptySet() : Collections.singleton(configFile));
this.configSignature = FileSignature.signAsList(configFile == null ? Collections.emptySet() : Set.of(configFile));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that Collections.emptySet() doesn't have a Set.empty() or something. 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does have an equivalent to emptySet(), actually. Just call Set.of()without any arguments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought so! interesting that the rule replaces Collections.singleton but not Collections.emptySet

}

FormatterFunc createFormat() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void itCalculatesSameNodeModulesDirForSameContent() throws IOException {
@Test
void itCalculatesDifferentNodeModulesDirForDifferentPackageJson() throws IOException {
File testDir = newFolder("build");
String packageJsonContent1 = prettierPackageJson(Collections.singletonMap("prettier-plugin-xy", "^2.0.0"));
String packageJsonContent2 = prettierPackageJson(Collections.singletonMap("prettier-plugin-xy", "^2.1.0"));
String packageJsonContent1 = prettierPackageJson(Map.of("prettier-plugin-xy", "^2.0.0"));
String packageJsonContent2 = prettierPackageJson(Map.of("prettier-plugin-xy", "^2.1.0"));
String serveJsContent = "fun main() { console.log('Hello, world!'); }";

NodeServerLayout layout1 = new NodeServerLayout(testDir, packageJsonContent1, serveJsContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.diffplug.gradle.spotless;

import java.util.Collections;
import java.util.Map;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.json.JacksonConfig;
Expand All @@ -36,7 +36,7 @@ protected AJacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension form
}

public T feature(String feature, boolean toggle) {
this.jacksonConfig.appendFeatureToToggle(Collections.singletonMap(feature, toggle));
this.jacksonConfig.appendFeatureToToggle(Map.of(feature, toggle));
formatExtension.replaceStep(createStep());
return self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static java.util.Objects.requireNonNull;

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -200,7 +199,7 @@ protected FormatterStep createStep() {

private void fixParserToJavascript() {
if (this.prettierConfig == null) {
this.prettierConfig = Collections.singletonMap("parser", DEFAULT_PRETTIER_JS_PARSER);
this.prettierConfig = Map.of("parser", DEFAULT_PRETTIER_JS_PARSER);
} else {
final Object currentParser = this.prettierConfig.get("parser");
if (PRETTIER_JS_PARSERS.contains(String.valueOf(currentParser))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.diffplug.gradle.spotless;

import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -165,7 +164,7 @@ public JacksonJsonGradleConfig(FormatExtension formatExtension) {
* Refers to com.fasterxml.jackson.core.JsonGenerator.Feature
*/
public JacksonJsonGradleConfig jsonFeature(String feature, boolean toggle) {
this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle));
this.jacksonConfig.appendJsonFeatureToToggle(Map.of(feature, toggle));
formatExtension.replaceStep(createStep());
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected FormatterStep createStep() {

private void fixParserToTypescript() {
if (this.prettierConfig == null) {
this.prettierConfig = new TreeMap<>(Collections.singletonMap("parser", "typescript"));
this.prettierConfig = new TreeMap<>(Map.of("parser", "typescript"));
} else {
final Object replaced = this.prettierConfig.put("parser", "typescript");
if (replaced != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/
package com.diffplug.gradle.spotless;

import java.util.Collections;
import java.util.Map;

import javax.inject.Inject;

Expand Down Expand Up @@ -62,7 +62,7 @@ public JacksonYamlGradleConfig(FormatExtension formatExtension) {
* Refers to com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature
*/
public JacksonYamlGradleConfig yamlFeature(String feature, boolean toggle) {
this.jacksonConfig.appendYamlFeatureToToggle(Collections.singletonMap(feature, toggle));
this.jacksonConfig.appendYamlFeatureToToggle(Map.of(feature, toggle));
formatExtension.replaceStep(createStep());
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,8 @@
package com.diffplug.gradle.spotless;

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.gradle.api.Project;
import org.gradle.api.services.BuildServiceParameters;
Expand Down Expand Up @@ -50,7 +50,7 @@ void testLineEndings() throws Exception {
File testFile = setFile("testFile").toContent("\r\n");
File outputFile = new File(spotlessTask.getCleanDirectory(), "testFile");

spotlessTask.setTarget(Collections.singleton(testFile));
spotlessTask.setTarget(Set.of(testFile));
Tasks.execute(spotlessTask);

assertFile(outputFile).hasContent("\n");
Expand All @@ -60,7 +60,7 @@ void testLineEndings() throws Exception {
void testStep() throws Exception {
File testFile = setFile("testFile").toContent("apple");
File outputFile = new File(spotlessTask.getCleanDirectory(), "testFile");
spotlessTask.setTarget(Collections.singleton(testFile));
spotlessTask.setTarget(Set.of(testFile));

spotlessTask.setSteps(List.of(ReplaceStep.create("double-p", "pp", "p")));
Tasks.execute(spotlessTask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.nio.file.Path;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -79,7 +79,7 @@ protected File baseDir(FormatterStepConfig stepConfig) {
}

protected NpmPathResolver npmPathResolver(FormatterStepConfig stepConfig) {
return new NpmPathResolver(npm(stepConfig), node(stepConfig), npmrc(stepConfig), Collections.singletonList(baseDir(stepConfig)));
return new NpmPathResolver(npm(stepConfig), node(stepConfig), npmrc(stepConfig), List.of(baseDir(stepConfig)));
}

protected boolean moreThanOneNonNull(Object... objects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static com.diffplug.common.base.Strings.isNullOrEmpty;
import static java.util.Arrays.stream;
import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.fail;

Expand Down Expand Up @@ -298,7 +297,7 @@ protected static Map<String, Object> buildPomXmlParams(String pluginVersion, Str
}

if (modules != null) {
List<Map<String, String>> moduleNames = stream(modules).map(name -> singletonMap(MODULE_NAME, name)).collect(toList());
List<Map<String, String>> moduleNames = stream(modules).map(name -> Map.of(MODULE_NAME, name)).collect(toList());
params.put(MODULES, moduleNames);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -163,7 +162,7 @@ private void createSubProjects() throws IOException {
String subProjectName = entry.getKey();
List<SubProjectFile> subProjectFiles = entry.getValue();

String content = createPomXmlContent("/multi-module/pom-child.xml.mustache", singletonMap(CHILD_ID, subProjectName));
String content = createPomXmlContent("/multi-module/pom-child.xml.mustache", Map.of(CHILD_ID, subProjectName));
setFile(subProjectName + "/pom.xml").toContent(content);

createSubProjectFiles(subProjectName, subProjectFiles);
Expand Down
4 changes: 4 additions & 0 deletions rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ recipeList:
- org.openrewrite.java.format.NormalizeLineBreaks
- org.openrewrite.java.format.RemoveTrailingWhitespace
- org.openrewrite.java.migrate.UpgradeToJava17
- org.openrewrite.java.migrate.util.JavaUtilAPIs
- org.openrewrite.java.migrate.util.MigrateInflaterDeflaterToClose
- org.openrewrite.java.migrate.util.ReplaceStreamCollectWithToList
- org.openrewrite.java.migrate.util.SequencedCollection
- org.openrewrite.java.recipes.JavaRecipeBestPractices
- org.openrewrite.java.recipes.RecipeTestingBestPractices
- org.openrewrite.java.security.JavaSecurityBestPractices
Expand Down
Loading