Skip to content

Commit 86fe8bd

Browse files
Magyarimikimuhlba91
authored andcommitted
fix: use switch pattern matching
1 parent 732eda2 commit 86fe8bd

3 files changed

Lines changed: 12 additions & 39 deletions

File tree

config/suppressions.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,4 @@
2525
<suppress checks="AnonInnerLength" files=".*[\\/]src[\\/]test[\\/]"/>
2626
<suppress checks="ClassDataAbstractionCoupling" files=".*[\\/]src[\\/]test[\\/]"/>
2727
<suppress checks="TrailingComment" files=".*[\\/]Checkstyle(RulesDefinition|Metadata)\.java"/>
28-
29-
<!-- Suppress these checks until the plugin is upgraded to 13.4.1 and works with the dependency and Java upgrades. -->
30-
<suppress checks="UseEnhancedSwitch" files=".*[\\/]src[\\/]main[\\/]"/>
31-
<suppress checks="MissingNullCaseInSwitch" files=".*[\\/]src[\\/]main[\\/]"/>
3228
</suppressions>

src/main/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtils.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,12 @@ private CheckstyleSeverityUtils() {
2828
}
2929

3030
public static String toSeverity(String priority) {
31-
final String result;
32-
33-
switch (priority) {
34-
case "BLOCKER":
35-
case "CRITICAL":
36-
result = SeverityLevel.ERROR.getName();
37-
break;
38-
case "MAJOR":
39-
result = SeverityLevel.WARNING.getName();
40-
break;
41-
case "MINOR":
42-
case "INFO":
43-
result = SeverityLevel.INFO.getName();
44-
break;
45-
default:
31+
return switch (priority) {
32+
case "BLOCKER", "CRITICAL" -> SeverityLevel.ERROR.getName();
33+
case "MAJOR" -> SeverityLevel.WARNING.getName();
34+
case "MINOR", "INFO" -> SeverityLevel.INFO.getName();
35+
case null, default ->
4636
throw new IllegalArgumentException("Priority not supported: " + priority);
47-
}
48-
49-
return result;
37+
};
5038
}
5139
}

src/main/java/org/sonar/plugins/checkstyle/metadata/CheckstyleMetadata.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -257,23 +257,12 @@ private static boolean isMoreThanVarCharSizeLimit(String... values) {
257257
* @return sonar property type
258258
*/
259259
private static RuleParamType getPropertyType(ModulePropertyDetails modulePropertyDetails) {
260-
final RuleParamType result;
261-
switch (modulePropertyDetails.getType()) {
262-
case "boolean":
263-
result = RuleParamType.BOOLEAN;
264-
break;
265-
case "int":
266-
case "long":
267-
result = RuleParamType.INTEGER;
268-
break;
269-
case "float":
270-
case "double":
271-
result = RuleParamType.FLOAT;
272-
break;
273-
default:
274-
result = RuleParamType.STRING;
275-
}
276-
return result;
260+
return switch (modulePropertyDetails.getType()) {
261+
case "boolean" -> RuleParamType.BOOLEAN;
262+
case "int", "long" -> RuleParamType.INTEGER;
263+
case "float", "double" -> RuleParamType.FLOAT;
264+
case null, default -> RuleParamType.STRING;
265+
};
277266
}
278267

279268
/**

0 commit comments

Comments
 (0)