Update Reformatter to honour case wrap settings with switch expressions (GH7326).#9484
Update Reformatter to honour case wrap settings with switch expressions (GH7326).#9484neilcsmith-net wants to merge 1 commit into
Conversation
mbien
left a comment
There was a problem hiding this comment.
even though this might be incomplete, its a good change since this makes the NEVER option usable (which is nice for arrow switches since it still wraps blocks correctly, see snippet I posted via comment).
We could consider changing the default to NEVER but this would probably require to update many tests.
| String choose(String str) { | ||
| return switch (str) { | ||
| Object str = "pattern matching switch"; | ||
| IntStream iso = IntStream.of(1, 2); | ||
| case null -> "case with null formatting"; |
There was a problem hiding this comment.
Not sure if intended but this code is not valid (several compiler errors, matching error and also syntax (e.g (String s) or case default)).
We had issues before where tests using invalid code started failing for the wildest reasons (example: compiler suddenly thought it was a compact-java file and generated an additional wrapping class). Unless this is intended for the purpose of the test it might be better to use valid code.
also would be good to add a case which uses curly braces+yield, e.g
String choose(String str) {
IntStream iso = IntStream.of(1, 2);
return switch (str) {
case null -> "case with null formatting";
case String string when (string.length() == iso.filter(i -> i / 2 == 0).count() || string.length() == 0) ->
"case with pattern matching + condition + lambda expression formatting";
case String s when s.length() == 1 -> "case with pattern matching + condition formatting";
case String s when s.length() == 2 -> {
yield "case with pattern matching + condition formatting";
}
default -> "default formatting";
};
}There was a problem hiding this comment.
Oops, partly bad copy/paste after converting to multiline. Will fix and add your example. Need to check the existing test code is valid too.
There was a problem hiding this comment.
should we add the missing t? Because I once used to think the java format[t]er had no tests since i couldn't find it :)
There was a problem hiding this comment.
Can rename, but if we do should look at doing so in a way that navigate to test works.
Update Reformatter to only add a newline to cases in switch expressions when
wrapCaseStatementsis set toWRAP_ALWAYS(default).Fixes #7326
Alternative might be to ignore the force wrap setting when we have an
ARROWrather thanCOLON. I'm not sure the default works as well in those cases.