Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatAnnotations merges type and non-type annotations in records #2336

Open
jskov opened this issue Nov 10, 2024 · 4 comments
Open

formatAnnotations merges type and non-type annotations in records #2336

jskov opened this issue Nov 10, 2024 · 4 comments

Comments

@jskov
Copy link
Contributor

jskov commented Nov 10, 2024

I find that FormatAnnotationsStep works OK with annotations on fields/getters that follow the form mentioned in this note.

But I have started using records in my project and have code like this:

public record EnumsDto(
        @JsonbProperty("external") @Valid @Nullable ExternalEnum external,
        @JsonbProperty("externalLower") @Valid @Nullable ExternalLowerEnum externalLower,
...

The above is the formatAnnotations() output.

But it should (if I understand things correctly) be:

public record EnumsDto(
        @JsonbProperty("external")
        @Valid @Nullable ExternalEnum external,
        @JsonbProperty("externalLower")
        @Valid @Nullable ExternalLowerEnum externalLower,
...

But since there is no protection keyword (public/private) to separate the non-type annotations from the type-annotations, they all get merged into the same line by FormatAnnotationsStep.

This is observed with version Gradle Plugin v7.0.0.BETA4

@jskov
Copy link
Contributor Author

jskov commented Nov 14, 2024

I think this can be fixed simply by only stripping newlines from type-annotations.
And thus leaving them for unknown annotations (which does not happen now).

I will work on a patch for this.

@jskov jskov closed this as completed Nov 14, 2024
@jskov jskov reopened this Nov 14, 2024
@nedtwigg
Copy link
Member

This is a breaking change that makes me nervous. If you can gate it behind a flag, then I can easily merge. If you can't, we need to consider the impact to existing users a bit. @mernst any thoughts?

@jskov
Copy link
Contributor Author

jskov commented Nov 15, 2024

Sounds reasonable.

@jskov
Copy link
Contributor Author

jskov commented Nov 27, 2024

I have had another look, and the code actually does the right thing.

That is, assuming the input does not mix non-type and type annotations on the same line:

record FormatAnnotationsTest(
  @JsonbProperty("r0")
  @Valid
  @Nullable
  Object r0,
  @JsonbProperty("r1") @Valid
  @Nullable
  Object r1,
  @JsonbProperty("r2") @Valid @Nullable Object r2,
  @Valid
  @Nullable
  String r3) {
}

The r0+r3 are formatted correctly with the current implementation.

r1+r2 is what I want to fix.

The existing code handles (explicitly) annotations split with newlines (and whitespace).

The above problems (r1+r2) are of another type; there is not the nice EOL/whitespace markers to guide changes.

So I expect to run into problems with formatting of method arguments.

I will add some more tests and see where it leads me.

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

No branches or pull requests

2 participants