Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public String format(
editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE();
} else {
editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map(
RuleProvider::createNewRuleInstance).collect(Collectors.toList()),
RuleProvider::createNewRuleInstance).toList(),
editorConfigOverrideMap);
}
EditorConfigDefaults editorConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public String format(
editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE();
} else {
editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map(
RuleProvider::createNewRuleInstance).collect(Collectors.toList()),
RuleProvider::createNewRuleInstance).toList(),
editorConfigOverrideMap);
}
EditorConfigDefaults editorConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public String format(
} else {
editorConfigOverride = createEditorConfigOverride(
editorConfig,
allRuleProviders.stream().map(RuleProvider::createNewRuleInstance).collect(Collectors.toList()),
allRuleProviders.stream().map(RuleProvider::createNewRuleInstance).toList(),
editorConfigOverrideMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String applyWithFile(String unix, File file) {
try {
return adapter.format(file, unix, isScript);
} catch (DiktatReporting.LintException e) {
throw Lint.shortcut(e.lints.stream().map(lint -> Lint.atLine(lint.line, lint.ruleId, lint.detail)).collect(Collectors.toList()));
throw Lint.shortcut(e.lints.stream().map(lint -> Lint.atLine(lint.line, lint.ruleId, lint.detail)).toList());
}
}
}
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 @@ -280,7 +280,7 @@ private List<String> getParams(File file) {
}
builder.add("-charset").add("UTF-8");
builder.add(ThrowingEx.get(file::getCanonicalPath));
return builder.build().collect(Collectors.toList());
return builder.build().toList();
}

private FormatterFunc.Closeable toFunc() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ImportsGroup(String importOrder, Set<String> knownGroupings) {
this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR, -1))
.map(this::normalizeStatic)
.filter(group -> !knownGroupings.contains(group))
.collect(Collectors.toList());
.toList();
knownGroupings.addAll(this.subGroups);
}

Expand Down Expand Up @@ -91,7 +91,7 @@ private List<String> sort(List<String> imports, String lineFormat) {

private ImportSorterImpl(List<String> importOrder, boolean wildcardsLast, boolean semanticSort,
Set<String> treatAsPackage, Set<String> treatAsClass) {
importsGroups = importOrder.stream().filter(Objects::nonNull).map(order -> new ImportsGroup(order, knownGroupings)).collect(Collectors.toList());
importsGroups = importOrder.stream().filter(Objects::nonNull).map(order -> new ImportsGroup(order, knownGroupings)).toList();
putStaticItemIfNotExists(importsGroups);
putCatchAllGroupIfNotExists(importsGroups);

Expand All @@ -101,7 +101,7 @@ private ImportSorterImpl(List<String> importOrder, boolean wildcardsLast, boolea
ordering = new LexicographicalOrderingComparator(wildcardsLast);
}

List<String> subgroups = importsGroups.stream().map(ImportsGroup::getSubGroups).flatMap(Collection::stream).collect(Collectors.toList());
List<String> subgroups = importsGroups.stream().map(ImportsGroup::getSubGroups).flatMap(Collection::stream).toList();
this.allImportOrderItems.addAll(subgroups);
}

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 @@ -141,7 +141,7 @@ private static String calculateDiff(ReflectionHelper reflectionHelper, Object mo
throw new RuntimeException(e);
}
})
.collect(Collectors.toList());
.toList();

List<Object> onlyInAfterContent = reflectionHelper.streamGraph(graphAfter)
.filter(triple -> {
Expand All @@ -151,7 +151,7 @@ private static String calculateDiff(ReflectionHelper reflectionHelper, Object mo
throw new RuntimeException(e);
}
})
.collect(Collectors.toList());
.toList();
if (!(onlyInBeforeContent.isEmpty() && onlyInAfterContent.isEmpty())) {
diffResult = onlyInBeforeContent.stream().map("< %s"::formatted)
.collect(Collectors.joining("\n"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private Object makeListOf(Type type, String parameterValueAsString) {
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
throw new RuntimeException(ex);
}
}).collect(Collectors.toList());
}).toList();
}

private Object makeSetOf(Type type, String parameterValueAsString) {
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));
}

FormatterFunc createFormat() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ String format(ProcessRunner runner, String input, File file) throws IOException,

// This will ensure that the next file name is retrieved on every format
final List<String> finalArgs = Stream.concat(args.stream(), Stream.of(file.getAbsolutePath()))
.collect(Collectors.toList());
.toList();

return runner.exec(input.getBytes(StandardCharsets.UTF_8), finalArgs).assertExitZero(StandardCharsets.UTF_8);
}
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 @@ -159,7 +159,7 @@ public void iterateFiles(Predicate<String> subpathsToInclude, BiConsumer<String,
TreeDef<File> treeDef = TreeDef.forFile(Errors.rethrow());
List<File> files = TreeStream.depthFirst(treeDef, rootFolder())
.filter(File::isFile)
.collect(Collectors.toList());
.toList();

ListIterator<File> iterator = files.listIterator(files.size());
int rootLength = rootFolder().getAbsolutePath().length() + 1;
Expand Down Expand Up @@ -210,13 +210,13 @@ private void taskIsUpToDate(String task, boolean upToDate) throws IOException {
public static List<String> outcomes(BuildResult build, TaskOutcome outcome) {
return build.taskPaths(outcome).stream()
.filter(s -> !s.equals(":spotlessInternalRegisterDependencies"))
.collect(Collectors.toList());
.toList();
}

public static List<BuildTask> outcomes(BuildResult build) {
return build.getTasks().stream()
.filter(t -> !t.getPath().equals(":spotlessInternalRegisterDependencies"))
.collect(Collectors.toList());
.toList();
}

static String buildResultToString(BuildResult result) {
Expand Down
Loading
Loading