Skip to content

Commit 22911af

Browse files
author
Vincent Potucek
committed
[prone] Apply UnnecessaryDefaultInEnumSwitch
1 parent f3d5c5d commit 22911af

File tree

18 files changed

+275
-345
lines changed

18 files changed

+275
-345
lines changed

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

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

18+
import static org.eclipse.jdt.core.util.CompilationUnitSorter.RELATIVE_ORDER;
19+
1820
import java.util.Comparator;
1921
import java.util.List;
2022
import java.util.StringTokenizer;
@@ -347,33 +349,18 @@ public int compare(BodyDeclaration bodyDeclaration1, BodyDeclaration bodyDeclara
347349
}
348350

349351
private static int sortPreservedCategory(int category) {
350-
switch (category) {
351-
case STATIC_FIELDS_INDEX:
352-
case STATIC_INIT_INDEX:
353-
return STATIC_FIELDS_INDEX;
354-
case FIELDS_INDEX:
355-
case INIT_INDEX:
356-
return FIELDS_INDEX;
357-
default:
358-
return category;
359-
}
352+
return switch (category) {
353+
case STATIC_FIELDS_INDEX, STATIC_INIT_INDEX -> STATIC_FIELDS_INDEX;
354+
case FIELDS_INDEX, INIT_INDEX -> FIELDS_INDEX;
355+
default -> category;
356+
};
360357
}
361358

362-
private boolean isSortPreserved(BodyDeclaration bodyDeclaration) {
363-
switch (bodyDeclaration.getNodeType()) {
364-
case ASTNode.FIELD_DECLARATION:
365-
case ASTNode.ENUM_CONSTANT_DECLARATION:
366-
case ASTNode.INITIALIZER:
367-
return true;
368-
default:
369-
return false;
370-
}
371-
}
359+
private boolean isSortPreserved(BodyDeclaration bodyDeclaration) {return switch(bodyDeclaration.getNodeType()){case ASTNode.FIELD_DECLARATION,ASTNode.ENUM_CONSTANT_DECLARATION,ASTNode.INITIALIZER->true;default->false;};}
372360

373361
private int preserveRelativeOrder(BodyDeclaration bodyDeclaration1, BodyDeclaration bodyDeclaration2) {
374-
int value1 = (Integer) bodyDeclaration1.getProperty(CompilationUnitSorter.RELATIVE_ORDER);
375-
int value2 = (Integer) bodyDeclaration2.getProperty(CompilationUnitSorter.RELATIVE_ORDER);
376-
return value1 - value2;
362+
return (Integer) bodyDeclaration1.getProperty(RELATIVE_ORDER) -
363+
(Integer) bodyDeclaration2.getProperty(RELATIVE_ORDER);
377364
}
378365

379366
private int compareNames(BodyDeclaration bodyDeclaration1, BodyDeclaration bodyDeclaration2, String name1, String name2) {

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

Lines changed: 21 additions & 22 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

@@ -300,15 +303,14 @@ public String getEndingFor(File file) {
300303
}
301304

302305
private static String convertEolToLineEnding(String eol, File file) {
303-
switch (eol.toLowerCase(Locale.ROOT)) {
304-
case "lf":
305-
return LineEnding.UNIX.str();
306-
case "crlf":
307-
return LineEnding.WINDOWS.str();
308-
default:
309-
LOGGER.warn(".gitattributes file has unspecified eol value: {} for {}, defaulting to platform native", eol, file);
310-
return LineEnding.PLATFORM_NATIVE.str();
311-
}
306+
return switch (eol.toLowerCase(Locale.ROOT)) {
307+
case "lf" -> UNIX.str();
308+
case "crlf" -> WINDOWS.str();
309+
default -> {
310+
LOGGER.warn(".gitattributes file has unspecified eol value: {} for {}, defaulting to platform native", eol, file);
311+
yield PLATFORM_NATIVE.str();
312+
}
313+
};
312314
}
313315

314316
private LineEnding findDefaultLineEnding(Config config) {
@@ -318,12 +320,12 @@ private LineEnding findDefaultLineEnding(Config config) {
318320
// autocrlf=true converts CRLF->LF during commit
319321
// and converts LF->CRLF during checkout
320322
// so CRLF is the default line ending
321-
return LineEnding.WINDOWS;
323+
return WINDOWS;
322324
} else if (autoCRLF == AutoCRLF.INPUT) {
323325
// autocrlf=input converts CRLF->LF during commit
324326
// and does no conversion during checkout
325327
// mostly used on Unix, so LF is the default encoding
326-
return LineEnding.UNIX;
328+
return UNIX;
327329
} else if (autoCRLF == AutoCRLF.FALSE) {
328330
// handle core.eol
329331
EOL eol = config.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EOL, EOL.NATIVE);
@@ -335,14 +337,11 @@ private LineEnding findDefaultLineEnding(Config config) {
335337

336338
/** Creates a LineEnding from an EOL. */
337339
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
340+
return switch (eol) {
341+
case CRLF -> WINDOWS;
342+
case LF -> UNIX;
343+
case NATIVE -> PLATFORM_NATIVE;
344+
};
346345
}
347346
}
348347

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) {

0 commit comments

Comments
 (0)