Skip to content

Commit 68035f7

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

File tree

14 files changed

+89
-95
lines changed

14 files changed

+89
-95
lines changed

gradle/error-prone.gradle

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,7 @@ tasks.withType(JavaCompile).configureEach {
3737
'StringJoin',
3838
'StringJoining',
3939
'UnnecessarilyFullyQualified',
40-
'UnnecessaryAssignment',
41-
'UnnecessaryBoxedAssignment',
42-
'UnnecessaryBoxedVariable',
43-
'UnnecessaryBreakInSwitch',
44-
'UnnecessaryCheckNotNull',
45-
'UnnecessaryCopy',
46-
'UnnecessaryDefaultInEnumSwitch',
4740
'UnnecessaryLambda',
48-
'UnnecessaryLongToIntConversion',
49-
'UnnecessaryMethodInvocationMatcher',
50-
'UnnecessaryMethodReference',
51-
'UnnecessaryParentheses',
52-
'UnnecessaryQualifier',
53-
'UnnecessarySetDefault',
54-
'UnnecessaryStaticImport',
55-
'UnnecessaryStringBuilder',
56-
'UnnecessaryTestMethodPrefix',
57-
'UnnecessaryTypeArgument',
58-
'WildcardImport',
5941
)
6042
// bug: this only happens when the file is dirty.
6143
// 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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists
8-
distributionSha256Sum=df67a32e86e3276d011735facb1535f64d0d88df84fa87521e90becc2d735444

gradlew

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

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

121118

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

181175
JAVACMD=$( cygpath --unix "$JAVACMD" )
182176

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

217211
set -- \
218212
"-Dorg.gradle.appname=$APP_BASE_NAME" \
219-
\
220-
<% if ( classpath ) {%>\
221-
-classpath "$CLASSPATH" \
222-
<% } %>\
223213
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
224214
"$@"
225215

gradlew.bat

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

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

7774

7875
@rem Execute Gradle
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" %*
76+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
8077

8178
:end
8279
@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,10 +15,6 @@
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-
2218
import java.io.File;
2319
import java.io.FileInputStream;
2420
import java.io.IOException;
@@ -95,9 +91,10 @@ public LazyAllTheSame(File projectDir, Supplier<Iterable<File>> toFormat) {
9591
protected String calculateState() throws Exception {
9692
var files = toFormat.get().iterator();
9793
if (files.hasNext()) {
98-
return new RuntimeInit(projectDir).atRuntime().getEndingFor(files.next());
94+
Runtime runtime = new RuntimeInit(projectDir).atRuntime();
95+
return runtime.getEndingFor(files.next());
9996
} else {
100-
return UNIX.str();
97+
return LineEnding.UNIX.str();
10198
}
10299
}
103100

@@ -305,12 +302,12 @@ public String getEndingFor(File file) {
305302
private static String convertEolToLineEnding(String eol, File file) {
306303
switch (eol.toLowerCase(Locale.ROOT)) {
307304
case "lf":
308-
return UNIX.str();
305+
return LineEnding.UNIX.str();
309306
case "crlf":
310-
return WINDOWS.str();
307+
return LineEnding.WINDOWS.str();
311308
default:
312309
LOGGER.warn(".gitattributes file has unspecified eol value: {} for {}, defaulting to platform native", eol, file);
313-
return PLATFORM_NATIVE.str();
310+
return LineEnding.PLATFORM_NATIVE.str();
314311
}
315312
}
316313

@@ -321,12 +318,12 @@ private LineEnding findDefaultLineEnding(Config config) {
321318
// autocrlf=true converts CRLF->LF during commit
322319
// and converts LF->CRLF during checkout
323320
// so CRLF is the default line ending
324-
return WINDOWS;
321+
return LineEnding.WINDOWS;
325322
} else if (autoCRLF == AutoCRLF.INPUT) {
326323
// autocrlf=input converts CRLF->LF during commit
327324
// and does no conversion during checkout
328325
// mostly used on Unix, so LF is the default encoding
329-
return UNIX;
326+
return LineEnding.UNIX;
330327
} else if (autoCRLF == AutoCRLF.FALSE) {
331328
// handle core.eol
332329
EOL eol = config.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EOL, EOL.NATIVE);
@@ -338,11 +335,14 @@ private LineEnding findDefaultLineEnding(Config config) {
338335

339336
/** Creates a LineEnding from an EOL. */
340337
private static LineEnding fromEol(EOL eol) {
341-
return switch (eol) {
342-
case CRLF -> WINDOWS;
343-
case LF -> UNIX;
344-
case NATIVE -> PLATFORM_NATIVE;
345-
};
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
346346
}
347347
}
348348

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ 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);
6162
};
6263

6364
if (ktfmtFormattingOptions != null) {

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

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

151151
/** Returns the "canonical" form for this particular result (only possible if isResolvable). */
152152
public String canonical() {
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-
};
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
159161
}
160162

161163
/** Returns a string which describes this result. */
162164
public String userMessage() {
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-
};
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
168173
}
169174
}

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,14 @@ 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-
return switch (architecture) {
245-
case ARM64 -> "arm64";
246-
case X64 -> "x64";
247-
};
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+
}
248252
}
249253

250254
/**
@@ -286,10 +290,16 @@ private String getDownloadUrl(String version, Platform platform) throws IOExcept
286290
* @throws IOException When the given OS is not supported by Biome.
287291
*/
288292
private String getDownloadUrlExtension(OS os) throws IOException {
289-
return switch (os) {
290-
case LINUX, MAC_OS -> "";
291-
case WINDOWS -> ".exe";
292-
};
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+
}
293303
}
294304

295305
/**
@@ -316,11 +326,16 @@ private Path getExecutablePath(String version, Platform platform) {
316326
* @throws IOException When the given OS is not supported by Biome.
317327
*/
318328
private String getOsCodeName(OS os) throws IOException {
319-
return switch (os) {
320-
case LINUX -> "linux";
321-
case MAC_OS -> "darwin";
322-
case WINDOWS -> "win32";
323-
};
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+
}
324339
}
325340

326341
/**

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
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-
2118
import java.io.File;
2219
import java.io.Serializable;
2320
import java.nio.charset.StandardCharsets;
@@ -81,15 +78,15 @@ private void assertRegexSet() {
8178

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

8784
/**
8885
* Returns a step which will apply the given steps only within the blocks selected by the regex / openClose pair.
8986
* Linting within the substeps is not supported.
9087
*/
9188
public FormatterStep applyWithin(List<FormatterStep> steps) {
92-
return createStep(APPLY, steps);
89+
return createStep(Kind.APPLY, steps);
9390
}
9491

9592
private FormatterStep createStep(Kind kind, List<FormatterStep> steps) {
@@ -99,7 +96,7 @@ private FormatterStep createStep(Kind kind, List<FormatterStep> steps) {
9996
RoundtripAndEqualityState::toFormatterFunc);
10097
}
10198

102-
enum Kind {
99+
private enum Kind {
103100
APPLY, PRESERVE
104101
}
105102

@@ -213,22 +210,24 @@ public String applyWithFile(String unix, File file) throws Exception {
213210
}
214211
List<String> groups = groupsZeroed();
215212
Matcher matcher = regex.matcher(unix);
216-
if (kind == APPLY) {
213+
switch (kind) {
214+
case APPLY:
217215
while (matcher.find()) {
218216
// apply the formatter to each group
219217
groups.add(formatter.compute(matcher.group(1), file));
220218
}
221219
// and then assemble the result right away
222220
return assembleGroups(unix);
223-
} else if (kind == PRESERVE) {
221+
case PRESERVE:
224222
while (matcher.find()) {
225223
// store whatever is within the open/close tags
226224
groups.add(matcher.group(1));
227225
}
228226
String formatted = formatter.compute(unix, file);
229227
return assembleGroups(formatted);
228+
default:
229+
throw new Error();
230230
}
231-
throw new Error();
232231
}
233232

234233
@Override

0 commit comments

Comments
 (0)