Skip to content

Conversation

@crogoz
Copy link
Contributor

@crogoz crogoz commented Oct 2, 2025

Before this PR

Annotated fields in records would be formatted the same as the annotated arguments of methods.
While this makes sense for annotated arguments of methods (reasoning in: here) for record parameters, it makes them hard to read:

public record QuoteRequest(
        @Schema(description = "US state of the product being quoted", example = "TX")
                RegulatoryState regulatoryState,
        @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason,
        @Schema(description = "Type of quote being requested", example = "NEW_BUSINESS") QuoteType quoteType,
        @Schema(description = "Date the quoted changes become active", example = "2023-06-25")
                LocalDate quoteEffectiveDate,
)

After this PR

Fixes: #922
Fixes: #1292

public record QuoteRequest(
        @Schema(description = "US state of the product being quoted", example = "TX")
        RegulatoryState regulatoryState,

        @Schema(description = "Reason for a quote", example = "New Business")
        String amendmentReason,

        @Schema(
                description = "Type of quote being requested",
                example = "NEW_BUSINESS",
                somethingElse = "new",
                other = "my other long string")
        QuoteType quoteType,

        @Schema(description = "Date the quoted changes become active", example = "2023-06-25")
        LocalDate quoteEffectiveDate) {}

We are now reformatting the annotated parameters in records only following the rules:

  1. if an annotated parameter is broken into multiple lines - add new lines (before & after but not the first/last line)
  2. an annotated parameter is broken into multiple lines when the columnLimit would exceed 60.

==COMMIT_MSG==
Format annotated fields in records
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Oct 2, 2025

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Format annotated fields in records

Check the box to generate changelog(s)

  • Generate changelog entry

@changelog-app
Copy link

changelog-app bot commented Oct 2, 2025

Successfully generated changelog entry!

What happened?

Your changelog entries have been stored in the database as part of our migration to ChangelogV3.

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.

@crogoz crogoz marked this pull request as ready for review October 2, 2025 17:16

public record QuoteRequest(
int value,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty lines are kept in the output, so if people decide to add a line between the parameters, the formatter won't remove them

@Deprecated
@JsonValue(name = "something")
@Schema(description = "US state of the product being quoted", example = "TX")
RegulatoryState regulatoryState,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new lines before & after the broken annotated field

@crogoz crogoz requested a review from CRogers October 7, 2025 09:25
@bulldozer-bot bulldozer-bot bot merged commit d1cde3c into develop Oct 7, 2025
8 checks passed
@bulldozer-bot bulldozer-bot bot deleted the cr/annotations branch October 7, 2025 14:39
@autorelease3
Copy link

autorelease3 bot commented Oct 7, 2025

Released 2.77.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java Record formatting issue Put annotations on record fields on their own lines

3 participants