Lineending keep and improving linebreaks in enums #23
Open
Conversation
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.
Suggestion from antigravity (CAUTION: may contain traces of AI :-D)
In
synventis-tools/eclipse/synventis-code-formatter.xml, the setting controlling this is:org.eclipse.jdt.core.formatter.alignment_for_enum_constantsIt was previously set to
0("Do not wrap"). Because the constants were on one line but exceeded the 100-character line limit, the formatter was forced to break the line somewhere else. It chose to break inside the enum arguments instead, sinceorg.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constantallowed wrapping.The Fix: I have changed
alignment_for_enum_constantsto49, which corresponds to "Wrap all elements, every element on a new line".This will force the formatter to treat the constants like this:
Why 49?
In the Eclipse compiler (
org.eclipse.jdt.core.formatter), alignment values are bitmasks that combine multiple layout rules into a single integer.When configuring how sequences of items (like method arguments or enum constants) are formatted, Eclipse uses a 4-bit "wrap strategy" combined with a 1-bit "force flag". Here's the breakdown of where 49 comes from:
1. The Strategy (48)
There are several base formatting strategies you can choose:
16 (WRAP_COMPACT): Wrap only when necessary, putting as many elements on a single line as possible without exceeding the max line length.80 (WRAP_NEXT_PER_LINE): Wrap all elements, keeping the first element on the same line as the opening brace, but putting all subsequent elements on new lines.48 (WRAP_ONE_PER_LINE): Wrap all elements, putting every single element on a new line.Since we explicitly want every enum constant completely broken out into its own vertical list, the correct baseline strategy to pick is 48 (WRAP_ONE_PER_LINE).
2. The Force Flag (+1)
In addition to the base strategy, Eclipse allows an optional "+1" flag called FORCE.
48), the formatter will only apply line breaks if the line exceeds the maximum line width.48 + 1 = 49), it tells Eclipse: "I don't care how short this line is; FORCE every element onto a new line unconditionally.