Skip to content

Commit febeee1

Browse files
author
Vincent Potucek
committed
[openrewrite] RecipeNullabilityBestPractices
1 parent 6d3a440 commit febeee1

File tree

45 files changed

+147
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+147
-83
lines changed

gradle/rewrite.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ apply plugin: 'org.openrewrite.rewrite'
22

33
rewrite {
44
activeRecipe('com.diffplug.spotless.openrewrite.SanityCheck')
5+
activeStyle('com.diffplug.spotless.openrewrite.SpotlessFormat')
56
exclusions.addAll(
67
'**.dirty.java',
8+
'**DiffMessageFormatterTest.java',
9+
'**EclipseJdtSortMembers.java',
710
'**FormatterProperties.java',
11+
'**PaddedCellTaskTest.java',
812
'**_gradle_node_plugin_example_**',
913
'**gradle/changelog.gradle',
1014
'**gradle/java-publish.gradle',

lib/src/compatDiktat1Dot2Dot5/java/com/diffplug/spotless/glue/diktat/compat/DiktatCompat1Dot2Dot5Adapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 DiffPlug
2+
* Copyright 2023-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.
@@ -53,7 +53,7 @@ static class FormatterCallback implements Function2<LintError, Boolean, Unit> {
5353
}
5454

5555
@Override
56-
public Unit invoke(LintError lintError, Boolean corrected) {
56+
public @Nullable Unit invoke(LintError lintError, Boolean corrected) {
5757
if (!corrected) {
5858
errors.add(lintError);
5959
}

lib/src/main/java/com/diffplug/spotless/Jvm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ private void verifyVersionRangesDoNotIntersect(NavigableMap<Integer, V> jvm2fmtV
120120
}
121121

122122
/** @return Highest formatter version recommended for this JVM (null, if JVM not supported) */
123-
@Nullable public V getRecommendedFormatterVersion() {
123+
public @Nullable V getRecommendedFormatterVersion() {
124124
Integer configuredJvmVersionOrNull = jvm2fmtMaxVersion.floorKey(Jvm.version());
125125
return configuredJvmVersionOrNull == null ? null : jvm2fmtMaxVersion.get(configuredJvmVersionOrNull);
126126
}
127127

128-
@Nullable public V getMinimumRequiredFormatterVersion() {
128+
public @Nullable V getMinimumRequiredFormatterVersion() {
129129
Integer configuredJvmVersionOrNull = jvm2fmtMinVersion.floorKey(Jvm.version());
130130
return configuredJvmVersionOrNull == null ? null : jvm2fmtMinVersion.get(configuredJvmVersionOrNull);
131131
}

lib/src/main/java/com/diffplug/spotless/PaddedCell.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.
@@ -105,12 +105,12 @@ private static PaddedCell check(Formatter formatter, File file, String original,
105105
}
106106
String appliedOnce = formatter.computeWithLint(original, file, exceptionPerStep);
107107
if (appliedOnce.equals(original)) {
108-
return Type.CONVERGE.create(file, Collections.singletonList(appliedOnce));
108+
return Type.CONVERGE.create(file, List.of(appliedOnce));
109109
}
110110

111111
String appliedTwice = formatter.computeWithLint(appliedOnce, file, exceptionPerStep);
112112
if (appliedOnce.equals(appliedTwice)) {
113-
return Type.CONVERGE.create(file, Collections.singletonList(appliedOnce));
113+
return Type.CONVERGE.create(file, List.of(appliedOnce));
114114
}
115115

116116
List<String> appliedN = new ArrayList<>();

lib/src/main/java/com/diffplug/spotless/ValuePerStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ValuePerStep<T> extends AbstractList<T> {
6161
}
6262

6363
@Override
64-
public T get(int index) {
64+
public @Nullable T get(int index) {
6565
if (multipleValues != null) {
6666
return (T) multipleValues[index];
6767
} else if (valueIdx == index) {

lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.nio.file.Path;
2525
import java.nio.file.attribute.PosixFilePermission;
2626
import java.util.ArrayList;
27-
import java.util.Collections;
2827
import java.util.HashSet;
28+
import java.util.Set;
2929

3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
@@ -299,7 +299,7 @@ private State createState() throws IOException, InterruptedException {
299299
validateBiomeExecutable(resolvedPathToExe);
300300
validateBiomeConfigPath(configPath, version);
301301
logger.debug("Using Biome executable located at '{}'", resolvedPathToExe);
302-
var exeSignature = FileSignature.signAsList(Collections.singleton(new File(resolvedPathToExe)));
302+
var exeSignature = FileSignature.signAsList(Set.of(new File(resolvedPathToExe)));
303303
makeExecutable(resolvedPathToExe);
304304
return new State(resolvedPathToExe, exeSignature, configPath, language);
305305
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) {
4040
return new EslintConfig(eslintConfigPath, this.eslintConfigJs);
4141
}
4242

43-
@Nullable public File getEslintConfigPath() {
43+
public @Nullable File getEslintConfigPath() {
4444
return eslintConfigPathSignature == null ? null : eslintConfigPathSignature.get().getOnlyFile();
4545
}
4646

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.File;
2121
import java.io.IOException;
2222
import java.io.Serializable;
23-
import java.util.Collections;
2423
import java.util.HashMap;
2524
import java.util.LinkedHashMap;
2625
import java.util.Map;
@@ -65,7 +64,7 @@ public static Map<String, String> defaultDevDependencies() {
6564
}
6665

6766
public static Map<String, String> defaultDevDependenciesWithEslint(String version) {
68-
return Collections.singletonMap("eslint", version);
67+
return Map.of("eslint", version);
6968
}
7069

7170
public static FormatterStep create(Map<String, String> devDependencies, Provisioner provisioner, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) {
3939
return new EslintTypescriptConfig(eslintConfigPath, this.getEslintConfigJs(), getTypescriptConfigPath());
4040
}
4141

42-
@Nullable public File getTypescriptConfigPath() {
42+
public @Nullable File getTypescriptConfigPath() {
4343
return typescriptConfigPathSignature == null ? null : this.typescriptConfigPathSignature.get().getOnlyFile();
4444
}
4545
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 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.
@@ -21,7 +21,6 @@
2121
import java.io.IOException;
2222
import java.nio.charset.StandardCharsets;
2323
import java.nio.file.Files;
24-
import java.util.Collections;
2524
import java.util.LinkedHashMap;
2625
import java.util.Map;
2726
import java.util.stream.Collectors;
@@ -45,7 +44,7 @@ JsonWriter putAll(Map<String, ?> values) {
4544
}
4645

4746
JsonWriter put(String name, Object value) {
48-
verifyValues(Collections.singletonMap(name, value));
47+
verifyValues(Map.of(name, value));
4948
this.valueMap.put(name, value);
5049
return this;
5150
}

0 commit comments

Comments
 (0)