简体   繁体   中英

Javadoc warning: no @param for type when using Lombok @Builder

when generating javadoc from sources (delomboked) I receive following warnings for the builder classes generated by the Lombok's @Builder

[ERROR] Error while creating javadoc report: 
Exit code: 1 - /path/to/project/ProjectData.java:85: warning: no @param for type
        public ProjectData.ProjectDataBuilder type(final ProjectType type) {

Here is a part of delomboked class causing warning:

/**
 * @return {@code this}.
 */
@java.lang.SuppressWarnings("all")
public ProjectData.ProjectDataBuilder type(final ProjectType type) {
    this.type = type;
    return this;
}

And here is what is assumed a proper, no warning-producing javadoc - with @param present

/**
 * @param type some meaningful description
 * @return {@code this}.
 */
@java.lang.SuppressWarnings("all")
public ProjectData.ProjectDataBuilder type(final ProjectType type) {
    this.type = type;
    return this;
}

Is there a way to make de-lombok generate these as well? There are a lot of such warning in my project and they kind of clouds all the relevant actual errors.

With the latest Lombok versions¹, delombok will copy the @param placed in the field Javadoc to the corresponding builder method.

This is an extension of the existing @Getter/@Setter feature, which already moved @param / @return to the corresponding setter/getter.

You can also optionally put fully custom documentation using -- SETTER -- / -- GETTER -- (the @param and @return tags must then be in the corresponding section in that case):

@Builder
@Data
@AllArgsConstructor
public class LombokJavadoc {
    /**
     * my nice field
     *
     * -- SETTER --
     * sets the something
     *
     * @param something a nice value
     * -- GETTER --
     * access for something
     *
     * @return a nice value
     */
    private String something;
}

Generates:

public class LombokJavadoc {
    /**
     * my nice field
     */
    private String something;


    @java.lang.SuppressWarnings("all")
    public static class LombokJavadocBuilder {
        […]

        /**
         * sets the something
         *
         * @param something a nice value
         * @return {@code this}.
         */
        @java.lang.SuppressWarnings("all")
        public LombokJavadoc.LombokJavadocBuilder something(final String something) {
            this.something = something;
            return this;
        }
    }

    […]

    /**
     * access for something
     *
     * @return a nice value
     */
    @java.lang.SuppressWarnings("all")
    public String getSomething() {
        return this.something;
    }

    /**
     * sets the something
     *
     * @param something a nice value
     */
    @java.lang.SuppressWarnings("all")
    public void setSomething(final String something) {
        this.something = something;
    }
    
    […]
}

¹ This appears to actually have been implemented in PR #2008 , which was part of v1.18.6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM