Skip to content

Commit d346ef8

Browse files
authored
Use List.of (#1852)
2 parents 8cdfdd0 + 1ce91c7 commit d346ef8

File tree

6 files changed

+35
-48
lines changed

6 files changed

+35
-48
lines changed

lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import java.nio.file.Files;
1919
import java.nio.file.Path;
20-
import java.util.ArrayList;
21-
import java.util.Collections;
2220
import java.util.List;
2321
import java.util.Map;
2422
import java.util.Objects;
@@ -53,17 +51,15 @@ public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter {
5351
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
5452

5553
static {
56-
List<EditorConfigProperty<?>> list = new ArrayList<>();
57-
list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY());
5854
//noinspection deprecation
59-
list.add(DisabledRulesEditorConfigPropertyKt.getDISABLED_RULES_PROPERTY());
60-
//noinspection KotlinInternalInJava,deprecation
61-
list.add(DisabledRulesEditorConfigPropertyKt.getKTLINT_DISABLED_RULES_PROPERTY());
62-
list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY());
63-
list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY());
64-
list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY());
65-
list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY());
66-
DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list);
55+
DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of(
56+
CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(),
57+
DisabledRulesEditorConfigPropertyKt.getDISABLED_RULES_PROPERTY(),
58+
DisabledRulesEditorConfigPropertyKt.getKTLINT_DISABLED_RULES_PROPERTY(),
59+
IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(),
60+
IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(),
61+
InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(),
62+
MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY());
6763
}
6864

6965
static class FormatterCallback implements Function2<LintError, Boolean, Unit> {

lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import java.lang.reflect.Method;
2020
import java.nio.file.Files;
2121
import java.nio.file.Path;
22-
import java.util.ArrayList;
23-
import java.util.Collections;
2422
import java.util.List;
2523
import java.util.Map;
2624
import java.util.Objects;
@@ -61,15 +59,14 @@ public class KtLintCompat0Dot49Dot0Adapter implements KtLintCompatAdapter {
6159
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
6260

6361
static {
64-
List<EditorConfigProperty<?>> list = new ArrayList<>();
65-
list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY());
66-
list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY());
67-
list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY());
68-
list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY());
69-
list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY());
70-
list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY());
71-
list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY());
72-
DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list);
62+
DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of(
63+
CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(),
64+
EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY(),
65+
IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(),
66+
IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(),
67+
InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(),
68+
MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY(),
69+
RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY());
7370
}
7471

7572
private static final Method RULEID_METHOD;

lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.nio.file.Files;
1919
import java.nio.file.Path;
20-
import java.util.ArrayList;
2120
import java.util.Collections;
2221
import java.util.List;
2322
import java.util.Map;
@@ -61,15 +60,14 @@ public class KtLintCompat0Dot50Dot0Adapter implements KtLintCompatAdapter {
6160
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
6261

6362
static {
64-
List<EditorConfigProperty<?>> list = new ArrayList<>();
65-
list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY());
66-
list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY());
67-
list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY());
68-
list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY());
69-
list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY());
70-
list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY());
71-
list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY());
72-
DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list);
63+
DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of(
64+
CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(),
65+
EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY(),
66+
IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(),
67+
IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(),
68+
InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(),
69+
MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY(),
70+
RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY());
7371
}
7472

7573
static class FormatterCallback implements Function2<LintError, Boolean, Unit> {

lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.nio.file.Files;
1919
import java.nio.file.Path;
20-
import java.util.ArrayList;
2120
import java.util.Collections;
2221
import java.util.List;
2322
import java.util.Map;
@@ -61,15 +60,14 @@ public class KtLintCompat1Dot0Dot0Adapter implements KtLintCompatAdapter {
6160
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
6261

6362
static {
64-
List<EditorConfigProperty<?>> list = new ArrayList<>();
65-
list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY());
66-
list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY());
67-
list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY());
68-
list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY());
69-
list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY());
70-
list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY());
71-
list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY());
72-
DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list);
63+
DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of(
64+
CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(),
65+
EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY(),
66+
IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(),
67+
IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(),
68+
InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(),
69+
MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY(),
70+
RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY());
7371
}
7472

7573
static class FormatterCallback implements Function2<LintError, Boolean, Unit> {

lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 DiffPlug
2+
* Copyright 2020-2023 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.
@@ -28,7 +28,7 @@ class FileFinder {
2828
private final List<Supplier<Optional<File>>> fileCandidateFinders;
2929

3030
private FileFinder(Builder builder) {
31-
this.fileCandidateFinders = Collections.unmodifiableList(new ArrayList<>(builder.candidateFinders));
31+
this.fileCandidateFinders = List.copyOf(builder.candidateFinders);
3232
}
3333

3434
static Builder finderForFilename(String fileName) {

lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package com.diffplug.spotless.npm;
1717

1818
import java.io.File;
19-
import java.util.ArrayList;
20-
import java.util.Collections;
2119
import java.util.List;
2220
import java.util.Optional;
2321

@@ -35,7 +33,7 @@ public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable,
3533
this.explicitNpmExecutable = explicitNpmExecutable;
3634
this.explicitNodeExecutable = explicitNodeExecutable;
3735
this.explicitNpmrcFile = explicitNpmrcFile;
38-
this.additionalNpmrcLocations = Collections.unmodifiableList(new ArrayList<>(additionalNpmrcLocations));
36+
this.additionalNpmrcLocations = List.copyOf(additionalNpmrcLocations);
3937
}
4038

4139
/**

0 commit comments

Comments
 (0)