Fix indentation and closing-paren placement for multi-resource try-with-resources - #1454
saloni-eng wants to merge 2 commits into
Conversation
…cement for multi-resource try-with-resources
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
This fix is directionally correct, but I’d strongly prefer keeping this PR focused on the try-with-resources formatting issue only. The re-indentation churn in Could you revert the unrelated formatting-only edits and keep just the targeted logic change plus the relevant regression/golden updates? That would make the fix easier to validate and reduce the risk of accidental behavioral changes. |
Fixes #1392.
Try-with-resources statements with more than one resource were
formatting inconsistently: the first resource stayed glued to
try (,and the closing
)was glued to the last resource, e.g.:This changes multi-resource try statements to break after
(, puteach resource on its own line, and place the closing
)back at thesame indentation as
try, matching how other multi-line constructs(e.g. argument lists) are formatted:
Single-resource try-with-resources statements are unaffected.
Changes
JavaInputAstVisitor.visitTry: conditionally open aplusFourindent and force a break after
(only when there's more than oneresource; close the indent level before the trailing break so the
closing
)renders at the outer indent instead of the resourceindent.
FormatterTest: addedmultivariableTryWithResourcescovering thenew formatting.
testdata/B21465217.output,testdata/B26159561.output: regeneratedgolden files that encoded the old (pre-fix) multi-resource layout.
Testing
mvn clean testpasses, including the CR/LF/CRLF idempotency checksin
FormatterIntegrationTest.