Fix indentation and closing-paren placement for multi-resource try-with-resources - #1454
saloni-eng wants to merge 4 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. |
@25f2005869-glitch |
|
Thanks for the explanation. I understand that the regression and golden updates may be needed for the fix. My concern is specifically the broad re-indentation churn in FormatterTest.java. Could you revert the formatting-only changes and keep only the test changes needed to demonstrate the regression? If any re-indentation is required, please point out which lines depend on the parsing change. |
|
Done! Ive reverted the unrelated formatting churn and kept only the targeted change (fe69c58), merged in the latest master to resolve a conflict in FormatterTest.java (1fac4a4). FormatterTest.java is now a pure addition, only the new multivariableTryWithResources test, nothing else in the file changed. JavaInputAstVisitor.java's diff is scoped entirely to visitTry: the multiVariable conditional break after (, and moving builder.close() before the trailing break/) so the closing paren renders at the outer indent instead of the resource indent. For the golden files (from the original commit, unaffected by this cleanup): every changed line is in a multi-resource try (...) block, which is the only path this fix touches (getResources().size() > 1): B21465217.output: the three-resource try (JimfsOutputStream out2 = ...; BufferedOutputStream bout = ...; OutputStreamWriter writer = ...) block. The file's other try (Writer sourceWriter = ...) block (single resource) is unchanged. No other lines in any of these files are touched. Verified with git diff upstream/master on each file individually. Let me know if the CI workflow approval needs anything further from my end! |
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.