rewrite-static-analysis
rewrite-static-analysis copied to clipboard
Extend TernaryOperatorsShouldNotBeNested to collapse switch cases
What problem are you trying to solve?
When multiple cases have the same output they are currently all present, they can be collapsed/concentrated into a single case
Describe the solution you'd like
"""
class Test {
public String determineSomething(String a) {
return "a".equals(a) ? null : "b".equals(a) ? "b" : "c".equals(a) ? "c" : null;
}
}
""",
"""
class Test {
public String determineSomething(String a, String b) {
return switch (a) {
case "b" -> "b";
case "c" -> "c";
default -> null;
};
}
}
"""