Skip to content

Lineending keep and improving linebreaks in enums #23

Open
fpichler wants to merge 2 commits intodevfrom
lineending-keep
Open

Lineending keep and improving linebreaks in enums #23
fpichler wants to merge 2 commits intodevfrom
lineending-keep

Conversation

@fpichler
Copy link
Member

@fpichler fpichler commented Mar 12, 2026

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_constants

It 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, since org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant allowed wrapping.

The Fix: I have changed alignment_for_enum_constants to 49, which corresponds to "Wrap all elements, every element on a new line".

This will force the formatter to treat the constants like this:

public enum TestEnum {
  OPENGRAPH_TITLE("og:title"),
  OPENGRAPH_TYPE("og:type"),
  // ... and so on
}

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.

  • If you don't add the 1 (so the value is just 48), the formatter will only apply line breaks if the line exceeds the maximum line width.
  • If you do add the 1 (so the value becomes 48 + 1 = 49), it tells Eclipse: "I don't care how short this line is; FORCE every element onto a new line unconditionally.

@fpichler fpichler requested a review from msladek March 12, 2026 23:41
@fpichler fpichler changed the title Lineending keep Lineending keep and improving linebreaks in enums Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants