Skip to content

Commit c05bbc2

Browse files
author
Vincent Potucek
committed
[prone] Apply UnnecessaryLambda
1 parent b91580d commit c05bbc2

File tree

8 files changed

+27
-73
lines changed

8 files changed

+27
-73
lines changed

gradle/error-prone.gradle

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
1-
import static java.lang.System.getenv
2-
31
apply plugin: 'net.ltgt.errorprone'
42

53
dependencies {
6-
errorprone('com.google.errorprone:error_prone_core:2.42.0')
4+
errorprone('com.google.errorprone:error_prone_core:2.41.0')
75
errorprone('tech.picnic.error-prone-support:error-prone-contrib:0.25.0')
86
}
97

108
tasks.withType(JavaCompile).configureEach {
119
options.errorprone {
12-
disable( // not patchable
13-
'FormatStringConcatenation',
10+
disable( // consider fix, or reasoning.
1411
'FunctionalInterfaceMethodChanged',
1512
'JavaxInjectOnAbstractMethod',
1613
'OverridesJavaxInjectableMethod',
17-
'ReturnValueIgnored',
18-
'Slf4jLogStatement',
19-
'MissingSummary',
20-
// patchable
21-
'LexicographicalAnnotationAttributeListing',
22-
'LexicographicalAnnotationListing',
23-
'NonStaticImport',
24-
'Slf4jLoggerDeclaration', // logger -> log
25-
'StaticImport',
26-
// critical, finds lots of bugs... unused configs and stuff.
27-
'Unused',
28-
'UnusedMethod',
29-
'UnusedParameters',
30-
'UnusedVariable',
3114
)
3215
error(
3316
'AmbiguousJsonCreator',
@@ -49,45 +32,15 @@ tasks.withType(JavaCompile).configureEach {
4932
'PrimitiveComparison',
5033
'RedundantStringConversion',
5134
'RedundantStringEscape',
35+
'ReturnValueIgnored',
5236
'SelfAssignment',
53-
'StringJoin',
5437
'StringJoining',
38+
'UnnecessarilyFullyQualified',
39+
'UnnecessaryLambda',
5540
)
56-
// fixme bug: this only happens when the file is dirty!
57-
// up2date checking (caching) must consider file changes, as file is currently corrupt!
58-
// fix SelfTest.java:L22 ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;)
59-
errorproneArgs.add('-XepExcludedPaths:.*/SelfTest.java')
60-
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
61-
errorproneArgs.addAll(
62-
'-XepPatchLocation:IN_PLACE',
63-
'-XepPatchChecks:' +
64-
'AmbiguousJsonCreator,' +
65-
'ArrayEquals,' +
66-
'AssertJNullnessAssertion,' +
67-
'AutowiredConstructor,' +
68-
'CanonicalAnnotationSyntax,' +
69-
'CollectorMutability,' +
70-
'ConstantNaming,' +
71-
'DirectReturn,' +
72-
'EmptyMethod,' +
73-
'ExplicitArgumentEnumeration,' +
74-
'ExplicitEnumOrdering,' +
75-
'FormatStringConcatenation,' +
76-
'IdentityConversion,' +
77-
'ImmutablesSortedSetComparator,' +
78-
'IsInstanceLambdaUsage,' +
79-
'MockitoMockClassReference,' +
80-
'MockitoStubbing,' +
81-
'NestedOptionals,' +
82-
'PrimitiveComparison,' +
83-
'RedundantStringConversion,' +
84-
'RedundantStringEscape,' +
85-
'SelfAssignment,' +
86-
'Slf4jLogStatement,' +
87-
'StringJoin,' +
88-
'StringJoining,' +
89-
'TimeZoneUsage,'
90-
)
91-
}
41+
// bug: this only happens when the file is dirty.
42+
// might be an up2date (caching) issue, as file is currently in corrupt state.
43+
// ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;)
44+
errorproneArgs.add('-XepExcludedPaths:.*/SelfTest.java|.*/GradleIntegrationHarness.java')
9245
}
9346
}

lib-extra/src/cdt/java/com/diffplug/spotless/extra/glue/cdt/EclipseCdtFormatterStepImpl.java

Lines changed: 3 additions & 2 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,6 +21,7 @@
2121
import java.util.stream.Collectors;
2222
import java.util.stream.Stream;
2323

24+
import org.eclipse.cdt.core.ToolFactory;
2425
import org.eclipse.cdt.core.formatter.CodeFormatter;
2526
import org.eclipse.jface.text.Document;
2627
import org.eclipse.jface.text.IDocument;
@@ -35,7 +36,7 @@ public EclipseCdtFormatterStepImpl(Properties settings) throws Exception {
3536
Map<String, String> settingsMap = stream.collect(Collectors.toMap(
3637
e -> String.valueOf(e.getKey()),
3738
e -> String.valueOf(e.getValue())));
38-
codeFormatter = org.eclipse.cdt.core.ToolFactory.createDefaultCodeFormatter(settingsMap);
39+
codeFormatter = ToolFactory.createDefaultCodeFormatter(settingsMap);
3940
}
4041

4142
/** Formatting C/C++ string */

lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.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.
@@ -85,7 +85,7 @@ void policyTest() {
8585
setFile(".gitattributes").toContent(StringPrinter.buildStringFromLines(
8686
"* eol=lf",
8787
"*.MF eol=crlf"));
88-
LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), () -> testFiles());
88+
LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), this::testFiles);
8989
Assertions.assertThat(policy.getEndingFor(newFile("someFile"))).isEqualTo("\n");
9090
Assertions.assertThat(policy.getEndingFor(newFile("subfolder/someFile"))).isEqualTo("\n");
9191
Assertions.assertThat(policy.getEndingFor(newFile("MANIFEST.MF"))).isEqualTo("\r\n");
@@ -100,7 +100,7 @@ void policyDefaultLineEndingTest() throws GitAPIException {
100100
"[core]",
101101
"autocrlf=true",
102102
"eol=lf"));
103-
LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), () -> testFiles());
103+
LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), this::testFiles);
104104
Assertions.assertThat(policy.getEndingFor(newFile("someFile"))).isEqualTo("\r\n");
105105
}
106106

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 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.
@@ -15,6 +15,8 @@
1515
*/
1616
package com.diffplug.gradle.spotless;
1717

18+
import static org.assertj.core.api.Assertions.assertThat;
19+
1820
import java.nio.charset.Charset;
1921

2022
import org.junit.jupiter.api.Test;
@@ -51,7 +53,7 @@ void globalIsRespected() throws Exception {
5153
" encoding 'US-ASCII'",
5254
"}");
5355
setFile("test.java").toContent("µ");
54-
gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput().contains("Encoding error!");
56+
assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()).doesNotContain("Encoding error!");
5557
assertFile("test.java").hasContent("µ");
5658
}
5759

@@ -75,7 +77,7 @@ void globalIsRespectedButCanBeOverridden() throws Exception {
7577
"}");
7678
setFile("test.java").toContent("µ");
7779
setFile("utf32.encoded").toContent("µ", Charset.forName("UTF-32"));
78-
gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput().contains("Encoding error!");
80+
assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()).doesNotContain("Encoding error!");
7981
assertFile("test.java").hasContent("µ");
8082
assertFile("utf32.encoded").hasContent("µ", Charset.forName("UTF-32"));
8183
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Set<File> resolve(boolean withTransitives, Collection<String> mavenCoordi
6666
excludeTransitive.add(EXCLUDE_ALL_TRANSITIVES);
6767
}
6868
List<Dependency> dependencies = mavenCoordinates.stream()
69-
.map(coordinateString -> new DefaultArtifact(coordinateString))
69+
.map(DefaultArtifact::new)
7070
.map(artifact -> new Dependency(artifact, null, null, excludeTransitive))
7171
.collect(toList());
7272
CollectRequest collectRequest = new CollectRequest(dependencies, null, repositories);

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,16 @@ public static Provisioner mavenCentral() {
143143
return MAVEN_CENTRAL.get();
144144
}
145145

146-
private static final Supplier<Provisioner> MAVEN_CENTRAL = Suppliers.memoize(() -> caching("mavenCentral", () -> createWithRepositories(repo -> repo.mavenCentral())));
146+
private static final Supplier<Provisioner> MAVEN_CENTRAL = Suppliers.memoize(() -> caching("mavenCentral", () -> createWithRepositories(RepositoryHandler::mavenCentral)));
147147

148148
/** Creates a Provisioner for the local maven repo for development purpose. */
149149
public static Provisioner mavenLocal() {
150-
return MAVEN_LOCAL.get();
150+
return createWithRepositories(RepositoryHandler::mavenLocal);
151151
}
152152

153-
private static final Supplier<Provisioner> MAVEN_LOCAL = () -> createWithRepositories(repo -> repo.mavenLocal());
154-
155153
/** Creates a Provisioner for the Sonatype snapshots maven repo for development purpose. */
156154
public static Provisioner snapshots() {
157-
return SNAPSHOTS.get();
155+
return createWithRepositories(repo -> repo.maven(setup -> setup.setUrl("https://oss.sonatype.org/content/repositories/snapshots")));
158156
}
159157

160-
private static final Supplier<Provisioner> SNAPSHOTS = () -> createWithRepositories(repo -> repo.maven(setup -> setup.setUrl("https://oss.sonatype.org/content/repositories/snapshots")));
161158
}

testlib/src/test/java/com/diffplug/spotless/FormatterPropertiesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public FormatterSettingsAssert(FormatterProperties actual) {
196196

197197
/** Check that the values form all valid files are part of the settings properties. */
198198
public FormatterSettingsAssert containsSpecificValuesOf(Collection<File> files) {
199-
files.forEach(file -> containsSpecificValuesOf(file));
199+
files.forEach(this::containsSpecificValuesOf);
200200
return this;
201201
}
202202

testlib/src/test/java/com/diffplug/spotless/generic/FenceStepTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.File;
1919
import java.util.Arrays;
2020

21+
import org.jetbrains.annotations.Nullable;
2122
import org.junit.jupiter.api.Test;
2223

2324
import com.diffplug.common.base.StringPrinter;
@@ -132,7 +133,7 @@ public String getName() {
132133
return uppercase ? "uppercase" : "lowercase";
133134
}
134135

135-
@org.jetbrains.annotations.Nullable @Override
136+
@Nullable @Override
136137
public String format(String rawUnix, File file) throws Exception {
137138
return uppercase ? rawUnix.toUpperCase() : rawUnix.toLowerCase();
138139
}

0 commit comments

Comments
 (0)