Skip to content

Commit 83d1b0b

Browse files
author
Vincent Potucek
committed
[prone] Apply UnnecessaryDefaultInEnumSwitch
1 parent a0ac600 commit 83d1b0b

File tree

14 files changed

+95
-89
lines changed

14 files changed

+95
-89
lines changed

gradle/error-prone.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,25 @@ tasks.withType(JavaCompile).configureEach {
3737
'StringJoin',
3838
'StringJoining',
3939
'UnnecessarilyFullyQualified',
40+
'UnnecessaryAssignment',
41+
'UnnecessaryBoxedAssignment',
42+
'UnnecessaryBoxedVariable',
43+
'UnnecessaryBreakInSwitch',
44+
'UnnecessaryCheckNotNull',
45+
'UnnecessaryCopy',
46+
'UnnecessaryDefaultInEnumSwitch',
4047
'UnnecessaryLambda',
48+
'UnnecessaryLongToIntConversion',
49+
'UnnecessaryMethodInvocationMatcher',
50+
'UnnecessaryMethodReference',
51+
'UnnecessaryParentheses',
52+
'UnnecessaryQualifier',
53+
'UnnecessarySetDefault',
54+
'UnnecessaryStaticImport',
55+
'UnnecessaryStringBuilder',
56+
'UnnecessaryTestMethodPrefix',
57+
'UnnecessaryTypeArgument',
58+
'WildcardImport',
4159
)
4260
// bug: this only happens when the file is dirty.
4361
// might be an up2date (caching) issue, as file is currently in corrupt state.

gradle/wrapper/gradle-wrapper.jar

176 Bytes
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists
8+
distributionSha256Sum=df67a32e86e3276d011735facb1535f64d0d88df84fa87521e90becc2d735444

gradlew

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ case "$( uname )" in #(
114114
NONSTOP* ) nonstop=true ;;
115115
esac
116116

117+
<% if ( classpath ) {%>\
118+
CLASSPATH="\\\"\\\""
119+
<% } %>\
117120

118121

119122
# Determine the Java command to use to start the JVM.
@@ -171,6 +174,9 @@ fi
171174
# For Cygwin or MSYS, switch paths to Windows format before running java
172175
if "$cygwin" || "$msys" ; then
173176
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
177+
<% if ( classpath ) {%>\
178+
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
179+
<% } %>\
174180

175181
JAVACMD=$( cygpath --unix "$JAVACMD" )
176182

@@ -210,6 +216,10 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
210216

211217
set -- \
212218
"-Dorg.gradle.appname=$APP_BASE_NAME" \
219+
\
220+
<% if ( classpath ) {%>\
221+
-classpath "$CLASSPATH" \
222+
<% } %>\
213223
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
214224
"$@"
215225

gradlew.bat

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ goto fail
7070
:execute
7171
@rem Setup the command line
7272

73+
<% if ( classpath ) {%>\
74+
set CLASSPATH=
75+
<% } %>\
7376

7477

7578
@rem Execute Gradle
76-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
79+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%"<% if ( classpath ) {%> -classpath "%CLASSPATH%"<% } %> -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
7780

7881
:end
7982
@rem End local scope for the variables with windows NT shell

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

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

18+
import static com.diffplug.spotless.LineEnding.PLATFORM_NATIVE;
19+
import static com.diffplug.spotless.LineEnding.UNIX;
20+
import static com.diffplug.spotless.LineEnding.WINDOWS;
21+
1822
import java.io.File;
1923
import java.io.FileInputStream;
2024
import java.io.IOException;
@@ -91,10 +95,9 @@ public LazyAllTheSame(File projectDir, Supplier<Iterable<File>> toFormat) {
9195
protected String calculateState() throws Exception {
9296
var files = toFormat.get().iterator();
9397
if (files.hasNext()) {
94-
Runtime runtime = new RuntimeInit(projectDir).atRuntime();
95-
return runtime.getEndingFor(files.next());
98+
return new RuntimeInit(projectDir).atRuntime().getEndingFor(files.next());
9699
} else {
97-
return LineEnding.UNIX.str();
100+
return UNIX.str();
98101
}
99102
}
100103

@@ -302,12 +305,12 @@ public String getEndingFor(File file) {
302305
private static String convertEolToLineEnding(String eol, File file) {
303306
switch (eol.toLowerCase(Locale.ROOT)) {
304307
case "lf":
305-
return LineEnding.UNIX.str();
308+
return UNIX.str();
306309
case "crlf":
307-
return LineEnding.WINDOWS.str();
310+
return WINDOWS.str();
308311
default:
309312
LOGGER.warn(".gitattributes file has unspecified eol value: {} for {}, defaulting to platform native", eol, file);
310-
return LineEnding.PLATFORM_NATIVE.str();
313+
return PLATFORM_NATIVE.str();
311314
}
312315
}
313316

@@ -318,12 +321,12 @@ private LineEnding findDefaultLineEnding(Config config) {
318321
// autocrlf=true converts CRLF->LF during commit
319322
// and converts LF->CRLF during checkout
320323
// so CRLF is the default line ending
321-
return LineEnding.WINDOWS;
324+
return WINDOWS;
322325
} else if (autoCRLF == AutoCRLF.INPUT) {
323326
// autocrlf=input converts CRLF->LF during commit
324327
// and does no conversion during checkout
325328
// mostly used on Unix, so LF is the default encoding
326-
return LineEnding.UNIX;
329+
return UNIX;
327330
} else if (autoCRLF == AutoCRLF.FALSE) {
328331
// handle core.eol
329332
EOL eol = config.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EOL, EOL.NATIVE);
@@ -335,14 +338,11 @@ private LineEnding findDefaultLineEnding(Config config) {
335338

336339
/** Creates a LineEnding from an EOL. */
337340
private static LineEnding fromEol(EOL eol) {
338-
// @formatter:off
339-
switch (eol) {
340-
case CRLF: return LineEnding.WINDOWS;
341-
case LF: return LineEnding.UNIX;
342-
case NATIVE: return LineEnding.PLATFORM_NATIVE;
343-
default: throw new IllegalArgumentException("Unknown eol " + eol);
344-
}
345-
// @formatter:on
341+
return switch (eol) {
342+
case CRLF -> WINDOWS;
343+
case LF -> UNIX;
344+
case NATIVE -> PLATFORM_NATIVE;
345+
};
346346
}
347347
}
348348

lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ private FormattingOptions createFormattingOptions() throws Exception {
5858
case META -> Formatter.META_FORMAT;
5959
case GOOGLE -> Formatter.GOOGLE_FORMAT;
6060
case KOTLIN_LANG -> Formatter.KOTLINLANG_FORMAT;
61-
default -> throw new IllegalStateException("Unknown formatting option " + style);
6261
};
6362

6463
if (ktfmtFormattingOptions != null) {

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,20 @@ public boolean isResolvable() {
150150

151151
/** Returns the "canonical" form for this particular result (only possible if isResolvable). */
152152
public String canonical() {
153-
// @formatter:off
154-
switch (type) {
155-
case CONVERGE: return steps.get(steps.size() - 1);
156-
case CYCLE: return Collections.min(steps, Comparator.comparingInt(String::length).thenComparing(Function.identity()));
157-
case DIVERGE: throw new IllegalArgumentException("No canonical form for a diverging result");
158-
default: throw new IllegalArgumentException("Unknown type: " + type);
159-
}
160-
// @formatter:on
153+
return switch (type) {
154+
case CONVERGE -> steps.get(steps.size() - 1);
155+
case CYCLE ->
156+
Collections.min(steps, Comparator.comparingInt(String::length).thenComparing(Function.identity()));
157+
case DIVERGE -> throw new IllegalArgumentException("No canonical form for a diverging result");
158+
};
161159
}
162160

163161
/** Returns a string which describes this result. */
164162
public String userMessage() {
165-
// @formatter:off
166-
switch (type) {
167-
case CONVERGE: return "converges after " + steps.size() + " steps";
168-
case CYCLE: return "cycles between " + steps.size() + " steps";
169-
case DIVERGE: return "diverges after " + steps.size() + " steps";
170-
default: throw new IllegalArgumentException("Unknown type: " + type);
171-
}
172-
// @formatter:on
163+
return switch (type) {
164+
case CONVERGE -> "converges after " + steps.size() + " steps";
165+
case CYCLE -> "cycles between " + steps.size() + " steps";
166+
case DIVERGE -> "diverges after " + steps.size() + " steps";
167+
};
173168
}
174169
}

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

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,10 @@ private String computeChecksum(Path file, String algorithm) throws IOException {
241241
* @throws IOException When the given OS is not supported by Biome.
242242
*/
243243
private String getArchitectureCodeName(Architecture architecture) throws IOException {
244-
switch (architecture) {
245-
case ARM64:
246-
return "arm64";
247-
case X64:
248-
return "x64";
249-
default:
250-
throw new IOException("Unsupported architecture: " + architecture);
251-
}
244+
return switch (architecture) {
245+
case ARM64 -> "arm64";
246+
case X64 -> "x64";
247+
};
252248
}
253249

254250
/**
@@ -290,16 +286,10 @@ private String getDownloadUrl(String version, Platform platform) throws IOExcept
290286
* @throws IOException When the given OS is not supported by Biome.
291287
*/
292288
private String getDownloadUrlExtension(OS os) throws IOException {
293-
switch (os) {
294-
case LINUX:
295-
return "";
296-
case MAC_OS:
297-
return "";
298-
case WINDOWS:
299-
return ".exe";
300-
default:
301-
throw new IOException("Unsupported OS: " + os);
302-
}
289+
return switch (os) {
290+
case LINUX, MAC_OS -> "";
291+
case WINDOWS -> ".exe";
292+
};
303293
}
304294

305295
/**
@@ -326,16 +316,11 @@ private Path getExecutablePath(String version, Platform platform) {
326316
* @throws IOException When the given OS is not supported by Biome.
327317
*/
328318
private String getOsCodeName(OS os) throws IOException {
329-
switch (os) {
330-
case LINUX:
331-
return "linux";
332-
case MAC_OS:
333-
return "darwin";
334-
case WINDOWS:
335-
return "win32";
336-
default:
337-
throw new IOException("Unsupported OS: " + os);
338-
}
319+
return switch (os) {
320+
case LINUX -> "linux";
321+
case MAC_OS -> "darwin";
322+
case WINDOWS -> "win32";
323+
};
339324
}
340325

341326
/**

lib/src/main/java/com/diffplug/spotless/generic/FenceStep.java

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

18+
import static com.diffplug.spotless.generic.FenceStep.Kind.APPLY;
19+
import static com.diffplug.spotless.generic.FenceStep.Kind.PRESERVE;
20+
1821
import java.io.File;
1922
import java.io.Serializable;
2023
import java.nio.charset.StandardCharsets;
@@ -78,15 +81,15 @@ private void assertRegexSet() {
7881

7982
/** Returns a step which will apply the given steps but preserve the content selected by the regex / openClose pair. */
8083
public FormatterStep preserveWithin(List<FormatterStep> steps) {
81-
return createStep(Kind.PRESERVE, steps);
84+
return createStep(PRESERVE, steps);
8285
}
8386

8487
/**
8588
* Returns a step which will apply the given steps only within the blocks selected by the regex / openClose pair.
8689
* Linting within the substeps is not supported.
8790
*/
8891
public FormatterStep applyWithin(List<FormatterStep> steps) {
89-
return createStep(Kind.APPLY, steps);
92+
return createStep(APPLY, steps);
9093
}
9194

9295
private FormatterStep createStep(Kind kind, List<FormatterStep> steps) {
@@ -96,7 +99,7 @@ private FormatterStep createStep(Kind kind, List<FormatterStep> steps) {
9699
RoundtripAndEqualityState::toFormatterFunc);
97100
}
98101

99-
private enum Kind {
102+
enum Kind {
100103
APPLY, PRESERVE
101104
}
102105

@@ -210,24 +213,22 @@ public String applyWithFile(String unix, File file) throws Exception {
210213
}
211214
List<String> groups = groupsZeroed();
212215
Matcher matcher = regex.matcher(unix);
213-
switch (kind) {
214-
case APPLY:
216+
if (kind == APPLY) {
215217
while (matcher.find()) {
216218
// apply the formatter to each group
217219
groups.add(formatter.compute(matcher.group(1), file));
218220
}
219221
// and then assemble the result right away
220222
return assembleGroups(unix);
221-
case PRESERVE:
223+
} else if (kind == PRESERVE) {
222224
while (matcher.find()) {
223225
// store whatever is within the open/close tags
224226
groups.add(matcher.group(1));
225227
}
226228
String formatted = formatter.compute(unix, file);
227229
return assembleGroups(formatted);
228-
default:
229-
throw new Error();
230230
}
231+
throw new Error();
231232
}
232233

233234
@Override

0 commit comments

Comments
 (0)