Lombok: [BUG] @Builder methods do not copy javadoc

Created on 3 Jun 2020  路  5Comments  路  Source: projectlombok/lombok

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!

Most helpful comment

Working on it right now, should be done soon

All 5 comments

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.

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.

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?

Yes, that is exactly what I expect.

Working on it right now, should be done soon

Was this page helpful?
0 / 5 - 0 ratings