Generate javadoc @return for Setter with lombok.accessors.chain=true

672 views
Skip to first unread message

PreXident

unread,
Mar 20, 2015, 2:07:17 PM3/20/15
to project...@googlegroups.com
Hello,
sorry if this is already explained somewhere, I did a quick search and found no relevant information.

I have started using lombok recently and I am fully satisfied except for one minor detail. I have a maven project, lombok version 1.16.2 and lombok.accessors.chain=true in lombok.config.

Here is a simple class annotated with lombok annotations
@ToString(of = "id")
@EqualsAndHashCode(of = "id")
public class Flight {

   
/**
     * Flight id.
     * @param id new Flight id.
     * @return Flight id
     */

   
@Getter @Setter protected long id;
}

Maven plugins are configured so javadoc and lombok cooperates well.
            <plugin>
               
<groupId>org.projectlombok</groupId>
               
<artifactId>lombok-maven-plugin</artifactId>
               
<version>1.16.2.0</version>
               
<configuration>
                   
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
                   
<outputDirectory>${delombok.output}</outputDirectory>
                   
<addOutputDirectory>false</addOutputDirectory>
               
</configuration>
               
<executions>
                   
<execution>
                       
<phase>generate-sources</phase>
                       
<goals>
                           
<goal>delombok</goal>
                       
</goals>
                   
</execution>
               
</executions>
           
</plugin>
           
<plugin>
               
<groupId>org.apache.maven.plugins</groupId>
               
<artifactId>maven-javadoc-plugin</artifactId>
               
<version>2.9</version>
               
<configuration>
                   
<sourcepath>${delombok.output}</sourcepath>
               
</configuration>
           
</plugin>

However a warning is produced on generating javadoc:

Javadoc Warnings
snip
/Flight.java:73: warning: no @return
public Flight setId(final long id) {
^

I would assume that "@return this" would be generated to javadoc of Setters by delombok when using accessors.chain to prevent this warning. Am I doing something wrong and this can be configured somehow somewhere? Or is this an oversight or still work in progress (as Accessors are still experimental)?

Thanks!

PreXident

unread,
Mar 30, 2015, 7:40:16 AM3/30/15
to project...@googlegroups.com
So I had to figure it myself and it was not that difficult fortunately. I have just added
            if (shouldReturnThis(from)) {
                filtered
[0] += "\n@return this";
           
}
to JavacHandlerUtil.CopyJavadoc_8.copyJavadoc and JavacHandlerUtil.copyJavadoc_jdk6_7. I am not sure if this is the most propriate place, but it seems to work.

0001-Added-generating-of-return-this-to-fluent-setters.patch

Reinier Zwitserloot

unread,
Jun 1, 2015, 10:40:14 AM6/1/15
to project-lombok
Good point, took the gist of your patch and added it, and added a test to make sure it works properly. It'll be in the next release.



 --Reinier Zwitserloot

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages