google-java-format icon indicating copy to clipboard operation
google-java-format copied to clipboard

Records with annotations on components are formatted pretty badly

Open laech opened this issue 2 years ago • 3 comments

Example output by google-java-format on a record:

public record MyRecord(
    @NotNull String firstName,
    String lastName,
    @NotEmpty List<String> friends,
    @MyAnnotation(
            propA = "The brown fox jumps over the lazy cat......",
            propB = 11,
            type = java.lang.Object.class)
        @HelloWorld
        String hello,
    String world,
    @Positive int numberA,
    @MyAnnotation(propA = "The brown fox jumps over the lazy cat", type = java.lang.Object.class)
        @HelloWorld
        String hello) {}

Compare to if it was a class:

public class MyClass {

  @NotNull String firstName;

  String lastName;

  @NotEmpty List<String> friends;

  @MyAnnotation(
      propA = "The brown fox jumps over the lazy cat......",
      propB = 11,
      type = Object.class)
  @HelloWorld
  String hello;

  String world;

  @Positive int numberA;

  @MyAnnotation(propA = "The brown fox jumps over the lazy cat", type = Object.class)
  @HelloWorld
  String hello;
}

laech avatar Mar 16 '23 08:03 laech

Yes, in records it looks awful!

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public record Game(
    @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.")
        String accountingGroup,
    @JsonProperty("accumulating")
        @JsonPropertyDescription("Marks which games with accumulating bonuses.")
        Boolean accumulating,
    @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.")
        Boolean bonusBuy,
    @JsonProperty("category")
        @JsonPropertyDescription(
            "Game's category. Allowed values: slots, roulette, card, "
                + "casual, lottery, poker, craps, video_poker")
        String category,
    @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd,
    @JsonProperty("hit_rate")
        @JsonPropertyDescription(
            "Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility "
                + "rating, and vice versa. Positive value. For slots only. "
                + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$")
        String hitRate,
    @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.")
        Map<String, String> params) {}

Can we expect any changes on this?

farrukh1388 avatar Dec 19 '24 18:12 farrukh1388

Same question...

vvkdev avatar Jan 27 '25 14:01 vvkdev

Same here, hope it can be formatted as fields in a general class with same intents, and allow whitespce lines between fields.

hantsy avatar May 02 '25 12:05 hantsy