Let insert_new_line_before_closing_brace_in_array_initializer support NEXT_LINE_ON_WRAP - #5196
Open
netomi wants to merge 1 commit into
Open
Conversation
… NEXT_LINE_ON_WRAP brace_position_for_array_initializer already supports NEXT_LINE_ON_WRAP for the opening brace: it moves to its own line only if the array initializer's content wraps across multiple lines, and stays inline otherwise. The closing brace had no equivalent - insert_new_line_before_closing_brace_in_array_initializer only accepted INSERT/DO_NOT_INSERT, so it was all-or-nothing regardless of whether the content actually wrapped. This adds NEXT_LINE_ON_WRAP as a third value, reusing the same deferred Token.setNextLineOnWrap()/isNextLineOnWrap() mechanism already used for the opening brace, resolved later by WrapExecutor once wrapping is decided. The existing boolean field and INSERT/DO_NOT_INSERT behavior are unchanged; the new value is tracked via a separate insert_new_line_before_closing_brace_in_array_initializer_on_wrap field to avoid touching the many existing call sites that set the old field directly. Fixes eclipse-jdt#5195 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Thomas Neidhart <thomas.neidhart@eclipse-foundation.org>
netomi
force-pushed
the
fix-array-initializer-closing-brace-wrap
branch
from
July 15, 2026 20:55
a940369 to
369b967
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5195
What
brace_position_for_array_initializeralready supportsNEXT_LINE_ON_WRAPfor the opening brace: it moves to its own line only if the array initializer's content wraps across multiple lines, staying inline otherwise. The closing brace had no equivalent —insert_new_line_before_closing_brace_in_array_initializeronly acceptedINSERT/DO_NOT_INSERT, so it was all-or-nothing regardless of whether the content actually wrapped.This PR adds
NEXT_LINE_ON_WRAPas a third accepted value forinsert_new_line_before_closing_brace_in_array_initializer, reusing the deferredToken.setNextLineOnWrap()/isNextLineOnWrap()mechanism already used for the opening brace, resolved later byWrapExecutoronce wrapping is decided.Before (with
brace_position_for_array_initializer=NEXT_LINE_ON_WRAP, closing brace unconditional):After (with the new value on the closing-brace option too):
How
DefaultCodeFormatterOptionsgains a newinsert_new_line_before_closing_brace_in_array_initializer_on_wrapboolean field, kept separate from the existinginsert_new_line_before_closing_brace_in_array_initializerfield so none of the existing call sites that set the old field directly (inFormatterBugsTests/FormatterRegressionTests) need to change.LineBreaksPreparator.visit(ArrayInitializer)callscloseBraceToken.setNextLineOnWrap()instead of the unconditionalbreakBefore()when the new flag is set.DefaultCodeFormatterConstantsjavadoc updated to document the new value.Testing
Added
testIssue5195_shortArrayStaysInlineandtestIssue5195_wrappedArrayGetsOwnLinetoFormatterBugsTests, covering both the unwrapped (no-op) and wrapped (brace gets its own line) cases. I also verified backward compatibility of the existingINSERT/DO_NOT_INSERTvalues is unaffected — both still produce identical output to before this change.I wasn't able to run the full Tycho-based test suite in my environment (this repo depends on a sibling
eclipse-platform-parentcheckout for its build), so I instead verified the formatter behavior directly: compiled the three modified classes against the released 3.43.0 artifacts (org.eclipse.jdt.core,ecj,org.eclipse.jface.text,org.eclipse.text), loaded them ahead of the stock jar viaToolFactory.createCodeFormatter, and confirmed the output for both the wrapped and unwrapped cases matches what's shown above, plus regression-checked the untouchedINSERT/DO_NOT_INSERTpaths produce byte-identical output to the unpatched formatter. Happy to have a maintainer confirm against the full test suite, and to adjust naming/approach based on review feedback.This PR was drafted with assistance from Claude (Anthropic).