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

[BUG] @Builder methods do not copy javadoc #2481

Closed
mathisdt opened this issue Jun 3, 2020 · 5 comments
Closed

[BUG] @Builder methods do not copy javadoc #2481

mathisdt opened this issue Jun 3, 2020 · 5 comments

Comments

@mathisdt
Copy link

mathisdt commented Jun 3, 2020

Describe the bug

  1. When using @Builder on a class while having a javadoc comment on a field, the resulting builder method does not show the javadoc of the field. (Delombok generates a javadoc comment in this case.)
  2. Likewise, when using @Builder on a constructor while having a javadoc comment on a constructor parameter, the resulting builder method does not show the javadoc of the parameter. (Neither Delombok not the Eclipse agent generate a javadoc comment in this case.)

To Reproduce

  1. @Builder on class:
@lombok.Builder
public class Test1 {
    /** Comment on Field */
    private int number;

    /** @param number Comment on Constructor */
    public Test1(final int number) {
        this.number = number;
    }

    private void bla() {
        Test1.builder()
            .number(1) // <--- no Javadoc displayed in tooltip without delombok, but delombok would generate Javadoc
            .build();
    }
}
  1. @Builder on constructor:
public class Test2 {
    /** Comment on Field */
    private int number;

    /** @param number Comment on Constructor */
    @lombok.Builder
    public Test2(final int number) {
        this.number = number;
    }

    private void bla() {
        Test2.builder()
            .number(1) // <--- no Javadoc displayed in tooltip without delombok, and delombok won't generate Javadoc
            .build();
    }
}

Expected behavior

  1. When using @Builder on a class while having a javadoc comment on a field, the resulting builder method should have a javadoc comment which contains the javadoc of the field. This should be consistent with the delombok behaviour (which generates a javadoc comment from the field's javadoc).
  2. Likewise, when using @Builder on a constructor while having a javadoc comment on a constructor parameter, the resulting builder method should have a javadoc comment which contains the javadoc of the parameter. This seems to be completely missing - neither delombok nor the Eclipse agent generate javadoc in this case.
    (It would also be OK if the javadoc comment of the identically-named field was copied, but that seems somewhat sloppy. Most of the time, there's a reason to use @Builder on the constructor, so the information should come from there.)

Version info (please complete the following information):

  • Lombok 1.18.12
  • Eclipse 2020-03 (4.15.0)

Additional context
I know that #2008 should have addressed this issue and was baffled when I learned that it doesn't work - at least for me. I also read through #1033 and #1445 but didn't find out how I may have failed, but I'm not a Lombok expert, so please tell me if I missed something!

@Rawi01
Copy link
Collaborator

Rawi01 commented Jun 3, 2020

The PR you mentioned added support for delombok/javac and doesn't change anything eclipse related. I can confirm that it doesn't work in eclipse. I also tried to find a feature that successfully copies javadoc but it seems to be broken or I did something wrong. I will check if I can figure out how this stuff works.

@mathisdt
Copy link
Author

mathisdt commented Jun 4, 2020

I just tested using delombok, and it works for the first described situation (@Builder on class). But when using @Builder on a constructor, nothing is copied into the javadoc of the builder method - neither from the field nor from the constructor's @param entry.
I updated the issue accordingly.

@Rawi01
Copy link
Collaborator

Rawi01 commented Jun 6, 2020

Seems like you are right.
If @Builder gets added to the constructor we can not identify the field because it might be named different or be part of the parent class. That means that it is not possible to copy the field javadoc. Nevertheless it should be possible to copy the parameter javadoc to the builder method, that might look like this one:

/**
 * @param number Comment on Constructor
 * @return {@code this}.
 */
public Test2.Test2Builder number(final int number) {
	this.number = number;
	return this;
}

Is that the behaviour you would expect?

@mathisdt
Copy link
Author

mathisdt commented Jun 6, 2020

Yes, that is exactly what I expect.

@Rawi01
Copy link
Collaborator

Rawi01 commented Jun 7, 2020

Working on it right now, should be done soon

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

No branches or pull requests

2 participants