Skip to content

Commit d511b46

Browse files
author
Vincent Potucek
committed
Add error-prone.picnic.tech featuring StaticImport
1 parent 90ff85a commit d511b46

File tree

236 files changed

+1369
-1120
lines changed

Some content is hidden

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

236 files changed

+1369
-1120
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ repositories {
1212
apply from: rootProject.file('gradle/java-publish.gradle')
1313
apply from: rootProject.file('gradle/changelog.gradle')
1414
allprojects {
15+
apply from: rootProject.file('gradle/error-prone.gradle')
1516
apply from: rootProject.file('gradle/rewrite.gradle')
1617
apply from: rootProject.file('gradle/spotless.gradle')
1718
}

gradle/error-prone.gradle

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import static java.lang.System.getenv
2+
3+
apply plugin: 'net.ltgt.errorprone'
4+
5+
dependencies {
6+
errorprone('com.google.errorprone:error_prone_core:2.42.0')
7+
errorprone('tech.picnic.error-prone-support:error-prone-contrib:0.25.0')
8+
errorprone('tech.picnic.error-prone-support:refaster-runner:0.25.0')
9+
}
10+
11+
tasks.withType(JavaCompile).configureEach {
12+
options.errorprone {
13+
disableWarningsInGeneratedCode = true
14+
error(
15+
'EmptyMethod',
16+
'EmptyMonoZip',
17+
'LexicographicalAnnotationAttributeListing',
18+
'LexicographicalAnnotationListing',
19+
'MissingOverride',
20+
'MissingSuperCall',
21+
'MissingTestCall',
22+
'NonEmptyMono',
23+
'OptionalMapUnusedValue',
24+
'OptionalOfRedundantMethod',
25+
'RedundantSetterCall',
26+
'RedundantStringConversion',
27+
'RedundantStringEscape',
28+
'StaticImport',
29+
'StringJoin',
30+
'UnnecessaryCheckNotNull',
31+
'UnnecessaryTypeArgument',
32+
'UnusedAnonymousClass',
33+
'UnusedCollectionModifiedInPlace',
34+
)
35+
errorproneArgs.add('-XepOpt:Refaster:NamePattern=^(?!.*Rules\\$).*')
36+
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
37+
errorproneArgs.addAll(
38+
'-XepPatchLocation:IN_PLACE',
39+
'-XepPatchChecks:' +
40+
'EmptyMethod,' +
41+
'EmptyMonoZip,' +
42+
'LexicographicalAnnotationAttributeListing,' +
43+
'LexicographicalAnnotationListing,' +
44+
'MissingOverride,' +
45+
'MissingSuperCall,' +
46+
'MissingTestCall,' +
47+
'NonEmptyMono,' +
48+
'OptionalMapUnusedValue,' +
49+
'OptionalOfRedundantMethod,' +
50+
'RedundantSetterCall,' +
51+
'RedundantStringConversion,' +
52+
'RedundantStringEscape,' +
53+
'StaticImport,' +
54+
'StringJoin,' +
55+
'UnnecessaryCheckNotNull,' +
56+
'UnnecessaryTypeArgument,' +
57+
'UnusedAnonymousClass,' +
58+
'UnusedCollectionModifiedInPlace,'
59+
)
60+
}
61+
}
62+
}

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

Lines changed: 4 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.
@@ -15,10 +15,11 @@
1515
*/
1616
package com.diffplug.spotless.extra.glue.cdt;
1717

18+
import static java.util.stream.Collectors.toMap;
19+
1820
import java.util.Map;
1921
import java.util.Map.Entry;
2022
import java.util.Properties;
21-
import java.util.stream.Collectors;
2223
import java.util.stream.Stream;
2324

2425
import org.eclipse.cdt.core.formatter.CodeFormatter;
@@ -32,7 +33,7 @@ public class EclipseCdtFormatterStepImpl {
3233

3334
public EclipseCdtFormatterStepImpl(Properties settings) throws Exception {
3435
Stream<Entry<Object, Object>> stream = settings.entrySet().stream();
35-
Map<String, String> settingsMap = stream.collect(Collectors.toMap(
36+
Map<String, String> settingsMap = stream.collect(toMap(
3637
e -> String.valueOf(e.getKey()),
3738
e -> String.valueOf(e.getValue())));
3839
codeFormatter = org.eclipse.cdt.core.ToolFactory.createDefaultCodeFormatter(settingsMap);

lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
*/
1616
package com.diffplug.spotless.extra.glue.groovy;
1717

18+
import static java.util.Collections.synchronizedList;
19+
1820
import java.io.ByteArrayInputStream;
1921
import java.io.ByteArrayOutputStream;
2022
import java.io.IOException;
2123
import java.nio.file.Files;
2224
import java.util.ArrayList;
23-
import java.util.Collections;
2425
import java.util.List;
2526
import java.util.Map;
2627
import java.util.Properties;
@@ -111,7 +112,7 @@ public GroovyErrorListener() {
111112
* We need a synchronized list here, in case multiple instantiations
112113
* run in parallel.
113114
*/
114-
errors = Collections.synchronizedList(new ArrayList<>());
115+
errors = synchronizedList(new ArrayList<>());
115116
ILog groovyLogger = GroovyCoreActivator.getDefault().getLog();
116117
groovyLogger.addLogListener(this);
117118
synchronized (GroovyLogManager.manager) {

lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtFormatterStepImpl.java

Lines changed: 4 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.
@@ -15,11 +15,12 @@
1515
*/
1616
package com.diffplug.spotless.extra.glue.jdt;
1717

18+
import static java.util.stream.Collectors.toMap;
19+
1820
import java.io.File;
1921
import java.util.HashMap;
2022
import java.util.Map;
2123
import java.util.Properties;
22-
import java.util.stream.Collectors;
2324

2425
import org.eclipse.jdt.core.formatter.CodeFormatter;
2526
import org.eclipse.jdt.internal.compiler.env.IModule;
@@ -37,7 +38,7 @@ public class EclipseJdtFormatterStepImpl {
3738
private final EclipseJdtSortMembers.SortProperties sortProperties;
3839

3940
public EclipseJdtFormatterStepImpl(Properties formatterSettings, Map<String, String> sortProperties) {
40-
Map<String, String> options = formatterSettings.entrySet().stream().collect(Collectors.toMap(
41+
Map<String, String> options = formatterSettings.entrySet().stream().collect(toMap(
4142
e -> String.valueOf(e.getKey()),
4243
e -> String.valueOf(e.getValue()),
4344
(prev, next) -> next,

lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtSortMembers.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,64 +98,84 @@ private static class Buffer implements IBuffer {
9898
this.contents = contents;
9999
}
100100

101+
@Override
101102
public void addBufferChangedListener(IBufferChangedListener listener) {}
102103

104+
@Override
103105
public void append(char[] text) {}
104106

107+
@Override
105108
public void append(String text) {}
106109

110+
@Override
107111
public void close() {}
108112

113+
@Override
109114
public char getChar(int position) {
110115
return '\u0000';
111116
}
112117

118+
@Override
113119
public char[] getCharacters() {
114120
return contents.toCharArray();
115121
}
116122

123+
@Override
117124
public String getContents() {
118125
return contents;
119126
}
120127

128+
@Override
121129
public int getLength() {
122130
return 0;
123131
}
124132

133+
@Override
125134
public IOpenable getOwner() {
126135
return null;
127136
}
128137

138+
@Override
129139
public String getText(int offset, int length) {
130140
return null;
131141
}
132142

143+
@Override
133144
public IResource getUnderlyingResource() {
134145
return null;
135146
}
136147

148+
@Override
137149
public boolean hasUnsavedChanges() {
138150
return false;
139151
}
140152

153+
@Override
141154
public boolean isClosed() {
142155
return false;
143156
}
144157

158+
@Override
145159
public boolean isReadOnly() {
146160
return true;
147161
}
148162

163+
@Override
149164
public void removeBufferChangedListener(IBufferChangedListener listener) {}
150165

166+
@Override
151167
public void replace(int position, int length, char[] text) {}
152168

169+
@Override
153170
public void replace(int position, int length, String text) {}
154171

172+
@Override
155173
public void save(IProgressMonitor progress, boolean force) {}
156174

175+
@Override
157176
public void setContents(char[] contents) {}
158177

178+
@Override
159179
public void setContents(String contents) {
160180
this.contents = contents;
161181
}

lib-extra/src/main/java/com/diffplug/spotless/extra/EclipseBasedStepBuilder.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
*/
1616
package com.diffplug.spotless.extra;
1717

18+
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java.util.Objects.requireNonNull;
20+
1821
import java.io.ByteArrayOutputStream;
1922
import java.io.File;
2023
import java.io.IOException;
2124
import java.io.InputStream;
2225
import java.io.Serializable;
23-
import java.nio.charset.StandardCharsets;
2426
import java.util.ArrayList;
2527
import java.util.List;
26-
import java.util.Objects;
2728
import java.util.Properties;
2829

2930
import com.diffplug.common.base.Errors;
@@ -69,10 +70,10 @@ public EclipseBasedStepBuilder(String formatterName, Provisioner jarProvisioner,
6970

7071
/** Initialize valid default configuration, taking latest version */
7172
public EclipseBasedStepBuilder(String formatterName, String formatterStepExt, Provisioner jarProvisioner, SerializedFunction<State, FormatterFunc> stateToFormatter) {
72-
this.formatterName = Objects.requireNonNull(formatterName, "formatterName");
73-
this.formatterStepExt = Objects.requireNonNull(formatterStepExt, "formatterStepExt");
74-
this.jarProvisioner = Objects.requireNonNull(jarProvisioner, "jarProvisioner");
75-
this.stateToFormatter = Objects.requireNonNull(stateToFormatter, "stateToFormatter");
73+
this.formatterName = requireNonNull(formatterName, "formatterName");
74+
this.formatterStepExt = requireNonNull(formatterStepExt, "formatterStepExt");
75+
this.jarProvisioner = requireNonNull(jarProvisioner, "jarProvisioner");
76+
this.stateToFormatter = requireNonNull(stateToFormatter, "stateToFormatter");
7677
formatterVersion = "No version set"; //Will fail creation
7778
}
7879

@@ -91,7 +92,7 @@ public void setVersion(String version) {
9192
throw new IllegalArgumentException("No such version " + version + ", expected at " + url);
9293
}
9394
byte[] content = toByteArray(depsFile);
94-
String allLines = new String(content, StandardCharsets.UTF_8);
95+
String allLines = new String(content, UTF_8);
9596
String[] lines = allLines.split("\n");
9697
dependencies.clear();
9798
for (String line : lines) {

lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.diffplug.spotless.extra;
1717

18+
import static java.util.Objects.requireNonNullElse;
1819
import static java.util.stream.Collectors.toMap;
1920

2021
import java.io.File;
@@ -24,7 +25,6 @@
2425
import java.util.Collection;
2526
import java.util.List;
2627
import java.util.Map;
27-
import java.util.Objects;
2828
import java.util.Properties;
2929

3030
import javax.annotation.Nullable;
@@ -190,8 +190,8 @@ static class EquoStep implements Serializable {
190190
ImmutableMap<String, String> stepProperties) {
191191

192192
this.semanticVersion = semanticVersion;
193-
this.settingProperties = Objects.requireNonNullElse(settingProperties, new ArrayList<>());
194-
this.settingXml = Objects.requireNonNullElse(settingXml, new ArrayList<>());
193+
this.settingProperties = requireNonNullElse(settingProperties, new ArrayList<>());
194+
this.settingXml = requireNonNullElse(settingXml, new ArrayList<>());
195195
this.settingsPromise = settingsPromise;
196196
this.jarPromise = jarPromise;
197197
this.stepProperties = stepProperties;
@@ -218,8 +218,8 @@ public static class State implements Serializable {
218218
public State(String semanticVersion, JarState jarState, List<String> settingProperties, List<String> settingXml, FileSignature settingsFiles, ImmutableMap<String, String> stepProperties) {
219219
this.semanticVersion = semanticVersion;
220220
this.jarState = jarState;
221-
this.settingProperties = Objects.requireNonNullElse(settingProperties, new ArrayList<>());
222-
this.settingXml = Objects.requireNonNullElse(settingXml, new ArrayList<>());
221+
this.settingProperties = requireNonNullElse(settingProperties, new ArrayList<>());
222+
this.settingXml = requireNonNullElse(settingXml, new ArrayList<>());
223223
this.settingsFiles = settingsFiles;
224224
this.stepProperties = stepProperties;
225225
}

lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
*/
1616
package com.diffplug.spotless.extra;
1717

18+
import static java.util.Collections.emptyList;
19+
import static java.util.Objects.requireNonNull;
20+
1821
import java.io.File;
1922
import java.io.FileInputStream;
2023
import java.io.IOException;
2124
import java.io.InputStream;
2225
import java.io.Serializable;
23-
import java.util.Collections;
2426
import java.util.HashMap;
2527
import java.util.List;
2628
import java.util.Locale;
2729
import java.util.Map;
28-
import java.util.Objects;
2930
import java.util.function.Supplier;
3031

3132
import javax.annotation.Nullable;
@@ -120,8 +121,8 @@ static class RelocatablePolicy extends LazyForwardingEquality<CachedEndings> imp
120121
transient Supplier<Iterable<File>> toFormat;
121122

122123
RelocatablePolicy(File projectDir, Supplier<Iterable<File>> toFormat) {
123-
this.projectDir = Objects.requireNonNull(projectDir, "projectDir");
124-
this.toFormat = Objects.requireNonNull(toFormat, "toFormat");
124+
this.projectDir = requireNonNull(projectDir, "projectDir");
125+
this.toFormat = requireNonNull(toFormat, "toFormat");
125126
}
126127

127128
@Override
@@ -260,10 +261,10 @@ static final class Runtime {
260261
final String defaultEnding;
261262

262263
private Runtime(List<AttributesRule> infoRules, @Nullable File workTree, Config config, List<AttributesRule> globalRules) {
263-
this.infoRules = Objects.requireNonNull(infoRules);
264+
this.infoRules = requireNonNull(infoRules);
264265
this.workTree = workTree;
265266
this.defaultEnding = findDefaultLineEnding(config).str();
266-
this.globalRules = Objects.requireNonNull(globalRules);
267+
this.globalRules = requireNonNull(globalRules);
267268
}
268269

269270
private static final String KEY_EOL = "eol";
@@ -389,7 +390,7 @@ private static List<AttributesRule> parseRules(@Nullable File file) {
389390
LOGGER.warn("Problem parsing {}", file.getAbsolutePath(), e);
390391
}
391392
}
392-
return Collections.emptyList();
393+
return emptyList();
393394
}
394395

395396
/** Parses an attribute value from a list of rules, returning null if there is no match for the given key. */

lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ private static IOException emptyFile(File commonDir) {
202202
return new IOException("Empty 'commondir' file: " + commonDir.getAbsolutePath());
203203
}
204204

205-
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
206205
@Override
206+
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
207207
public FileRepositoryBuilder readEnvironment(SystemReader sr) {
208208
super.readEnvironment(sr);
209209

0 commit comments

Comments
 (0)