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

Copy Javadoc to builder setters #2004

Closed
wants to merge 20 commits into from

Conversation

emlun
Copy link
Contributor

@emlun emlun commented Jan 3, 2019

Fixes #1033. Fixes #1445.

This causes Javadoc to be copied to @Builder setters using SETTER copy mode. See the added tests for an example.

Notes:

  • The change is currently only made in the makeSimpleSetterMethodForBuilder method, so I don't think this will apply to "singular" setters or other special cases - I haven't quite been able to grok how the else branch in makeSetterMethodsForBuilder method works.
  • It looked like the ECJ variant strips Javadoc altogether, so I didn't apply the same change there.
  • The tests currently do not cover interactions such as between @Builder and @Value/@Getter. I'll try to add some for that.

@emlun
Copy link
Contributor Author

emlun commented Jan 3, 2019

Turns out this doesn't play nicely with @Setter - @param tags get moved to the builder setter and are omitted from the instance setter. I'll see if I can fix that...

emlun added 13 commits January 3, 2019 18:10
This handler makes a final pass over the source and removes `@return`
and `@param` tags as well as `GETTER`/`SETTER`/`WITHER` sections from
the docstrings on fields. This changes javadoc behaviour slightly:

- `@return` and `@param` tags are now removed even if the generated
  method got its docstring from a `GETTER`/`SETTER`/`WITHER` section.
- `@return` and `@param` tags and `GETTER`/`SETTER`/`WITHER` sections
  are now always removed from all fields regardless of whether any
  generated member was created from the field. This should not be a
  problem for the most part, since `@return` and `@param` tags are
  normally nonsensical on field members, and `GETTER`/`SETTER`/`WITHER`
  sections are specific to Lombok.
This, together with the parent commit, means that multiple generated
members can now "extract" the same elements from the javadoc on a field.
For example, a `@Setter` and a `@Wither` can now both receive a `@param`
tag from the javadoc on their defining field, whereas previously the
first one to be processed would remove the tag from the field so it
didn't show up in the javadoc on the other.

This fixes the bug exposed by the test added in commit
480129a.
@emlun
Copy link
Contributor Author

emlun commented Jan 4, 2019

There - @Builder, @Setter and @Wither now all play nice together with the javadoc. This does mean the problem grew quite a bit in scope, though, so I also started a forum discussion which is currently awaiting approval.

@emlun
Copy link
Contributor Author

emlun commented Jan 4, 2019

emlun added 3 commits January 4, 2019 21:59
This sets up a new map from field nodes to the copy modes of the
docstrings for the members generated for that field. Javadoc cleanup is
now done only for the field nodes and copy modes in that map, instead of
for all field nodes and copy modes. This means that the Javadoc
extraction behaviour will remain the same as before. For example,

```
/**
 * A thing.
 * @return the thing
 * @param foo the new thing
 */
@Setter
private Foo foo;
```

will now be expanded to

```
/**
 * A thing.
 * @return the thing
 */
private Foo foo;
/**
 * A thing.
 * @param foo the new thing
 */
private void setFoo(final Foo foo) {
  this.foo = foo;
}
```

as in commit ca46f98, instead of being
expanded to

```
/**
 * A thing.
 */
private Foo foo;
/**
 * A thing.
 * @param foo the new thing
 */
private void setFoo(final Foo foo) {
  this.foo = foo;
}
```

as is done in commit f87359d.
@rzwitserloot
Copy link
Collaborator

In commit ccfab5e I've added a cleanup tasks system for the javac run of lombok. This should make it a lot simpler to fix this problem properly. I've also fixed the setter vs. wither conflict and written a test to show the fix is working, as proof of concept.

Would it be okay if you merge/rewrite your PR to use it? I'm pretty sure it's a breeze with this update, just, swamped with work and it was a late evening. Muchos gracias and thanks for putting in the effort to fix this oldie :)

Also, can you add your name to the CONTRIBUTORS file in the root of the project?

@emlun
Copy link
Contributor Author

emlun commented Jan 8, 2019

Cool, thanks! It indeed looks like this will be a lot simpler with that new infrastructure. I'll close this and open a new PR.

@emlun emlun closed this Jan 8, 2019
@emlun emlun deleted the builder-javadoc branch May 15, 2020 10:09
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