Fix Java reformatter for empty records and nested lambdas#9421
Conversation
Special case reformatting of empty body records without whitespace
(eg. record Foo(int x) {} ) to not insert lines and keep body as is.
The behaviour is only changed for default same-line brace handling.
Fix continuation indenting with nested lambdas being the same by not specifying a specific indent. This already works correctly when wrapAfterLambdaArrow is set. This fixes the default behaviour.
dbalek
left a comment
There was a problem hiding this comment.
Looks reasonable. Thanks.
|
Thanks @matthiasblaesing Yes, as I said, the other modes are somewhat broken already. This should be the same behaviour as recent releases? I've tried not to touch them for now. If it's not a regression I would prefer to consider as a follow up issue. There's a bit more to think about what to do with them if they're empty (new line may be odd for that), and we need some tests for those other modes. |
|
@neilcsmith-net a sorry I overlooked that remark. And yes, the brokenness is identical before and after the change, so ignore that part of my comment. |
|
Thanks for reviews. Going to merge this. Will take a look at what's happening with the other brace modes shortly. Ideal approach might be to peek ahead to search for |
|
@matthiasblaesing hopefully #9480 addresses the issues about alternative brace position modes. |



Fixes for two niggles in the reformatter - empty record bodies and nested lambda continuation indents.
Empty records
Where a record has an empty body with no whitespace -
Stop the reformatter turning this into -
This change keeps the original code intact while reformatting all non-empty bodies as before. The change only affects the default same-line brace placement. The other modes are somewhat broken with records already.
NB. The
classLeftBracePlacementmethod is removed and the code added to the record handling. Despite its name, this isn't used for non-record classes anyway, and while the intention might have been to allow code reuse, the method isn't correct for this.Nested lambda continuations
Where code has nested lambdas, such as -
Stop the reformatter from flattening the continuation indents -
This behaviour is already correct if
wrapAfterLambdaArrowis set, but not in the default case.