Skip to content

Commit dc66780

Browse files
author
Vincent Potucek
committed
[prone] fix warning StaticImport
- #2745 Signed-off-by: Vincent Potucek <[email protected]>
1 parent e4edf85 commit dc66780

File tree

193 files changed

+1186
-969
lines changed

Some content is hidden

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

193 files changed

+1186
-969
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ concurrency:
1212
group: ${{ github.workflow }}-${{ github.ref }}
1313
cancel-in-progress: true
1414
jobs:
15-
sanityCheck:
15+
sanity-check:
16+
name: SanityCheck
1617
runs-on: ubuntu-latest
1718
env:
1819
buildcacheuser: ${{ secrets.BUILDCACHE_USER }}
@@ -35,7 +36,7 @@ jobs:
3536
- name: assemble testClasses
3637
run: ./gradlew assemble testClasses
3738
build:
38-
needs: sanityCheck
39+
needs: sanity-check
3940
strategy:
4041
fail-fast: false
4142
matrix:
@@ -107,7 +108,7 @@ jobs:
107108
# Status check that is required in branch protection rules.
108109
final-status:
109110
needs:
110-
- sanityCheck
111+
- sanity-check
111112
- build
112113
runs-on: ubuntu-latest
113114
if: always()

gradle/error-prone.gradle

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
apply plugin: 'net.ltgt.errorprone'
1+
import static java.lang.System.getenv
22

3-
dependencies {
4-
errorprone('com.google.errorprone:error_prone_core:2.42.0')
5-
errorprone('tech.picnic.error-prone-support:error-prone-contrib:0.26.0')
6-
}
3+
apply plugin: 'net.ltgt.errorprone'
74

85
tasks.withType(JavaCompile).configureEach {
96
options.errorprone {
10-
disable( // consider fix, or reasoning.
7+
disableAllWarnings = true // https://github.com/diffplug/spotless/issues/2745 https://github.com/google/error-prone/issues/5365
8+
disable(
9+
// consider fix, or reasoning.
10+
'AnnotateFormatMethod', // We don`t want to use ErrorProne's annotations.
11+
'CheckReturnValue', // We don`t want to use ErrorProne's annotations.
12+
'CollectorMutability', // for freedom global exclude, might whitelist. https://github.com/diffplug/spotless/pull/2744#discussion_r2553042130
13+
'DoNotCallSuggester', // We don`t want to use ErrorProne's annotations.
1114
'FunctionalInterfaceMethodChanged',
15+
'ImmutableEnumChecker', // We don`t want to use ErrorProne's annotations.
16+
'InlineMeSuggester', // We don`t want to use ErrorProne's annotations.
17+
'JUnitClassModifiers',
1218
'JavaxInjectOnAbstractMethod',
19+
'LexicographicalAnnotationAttributeListing',
20+
'NonStaticImport',
21+
'StaticImport',
22+
'LexicographicalAnnotationListing',
1323
'OverridesJavaxInjectableMethod',
24+
'ReturnValueIgnored', // We don`t want to use ErrorProne's annotations.
25+
// bug
26+
'FieldMissingNullable',
27+
'Slf4jLogStatement',
28+
'Slf4jLoggerDeclaration',
29+
'Var'
1430
)
1531
error(
1632
'AmbiguousJsonCreator',
@@ -26,25 +42,42 @@ tasks.withType(JavaCompile).configureEach {
2642
'IdentityConversion',
2743
'ImmutablesSortedSetComparator',
2844
'IsInstanceLambdaUsage',
45+
'MissingOverride',
2946
'MockitoMockClassReference',
3047
'MockitoStubbing',
3148
'NestedOptionals',
49+
'NonStaticImport',
3250
'PrimitiveComparison',
3351
'RedundantStringConversion',
3452
'RedundantStringEscape',
3553
'ReturnValueIgnored',
3654
'SelfAssignment',
55+
'StaticImport',
3756
'StringJoin',
3857
'StringJoining',
3958
'UnnecessarilyFullyQualified',
4059
'UnnecessaryLambda',
4160
)
4261
// bug: this only happens when the file is dirty.
4362
// might be an up2date (caching) issue, as file is currently in corrupt state.
44-
// ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;)
45-
errorproneArgs.add('-XepExcludedPaths:' +
46-
'.*/SelfTest.java|' +
47-
'.*/GradleIntegrationHarness.java'
63+
// ForbidGradleInternal(import
64+
excludedPaths.set(
65+
'.*/GradleIntegrationHarness.java|'+
66+
'.*/SelfTest.java'
4867
)
68+
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
69+
errorproneArgs.addAll(
70+
'-XepPatchLocation:IN_PLACE', // how to prevent/ignore? @CanIgnoreReturnValue
71+
'-XepPatchChecks:' +
72+
'MissingOverride,' +
73+
'NonStaticImport,' +
74+
'StaticImport'
75+
)
76+
}
4977
}
5078
}
79+
80+
dependencies {
81+
errorprone('com.google.errorprone:error_prone_core:2.42.0')
82+
errorprone('tech.picnic.error-prone-support:error-prone-contrib:0.26.0')
83+
}

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
@@ -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.ToolFactory;
@@ -33,7 +34,7 @@ public class EclipseCdtFormatterStepImpl {
3334

3435
public EclipseCdtFormatterStepImpl(Properties settings) throws Exception {
3536
Stream<Entry<Object, Object>> stream = settings.entrySet().stream();
36-
Map<String, String> settingsMap = stream.collect(Collectors.toMap(
37+
Map<String, String> settingsMap = stream.collect(toMap(
3738
e -> String.valueOf(e.getKey()),
3839
e -> String.valueOf(e.getValue())));
3940
codeFormatter = 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
}

0 commit comments

Comments
 (0)