Skip to content

Commit 850238b

Browse files
committed
[fixes #3147] Copy javadoc to generated SuperBuilder
1 parent 000ce6d commit 850238b

File tree

9 files changed

+280
-19
lines changed

9 files changed

+280
-19
lines changed

src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java

+9
Original file line numberDiff line numberDiff line change
@@ -2959,4 +2959,13 @@ public static void copyJavadoc(EclipseNode from, ASTNode to, TypeDeclaration typ
29592959
setDocComment(cud, type, to, newJavadoc);
29602960
} catch (Exception ignore) {}
29612961
}
2962+
2963+
public static void copyJavadocFromParam(EclipseNode from, MethodDeclaration to, TypeDeclaration type, String param) {
2964+
try {
2965+
CompilationUnitDeclaration cud = (CompilationUnitDeclaration) from.top().get();
2966+
String methodComment = getDocComment(from);
2967+
String newJavadoc = addReturnsThisIfNeeded(getParamJavadoc(methodComment, param));
2968+
setDocComment(cud, type, to, newJavadoc);
2969+
} catch (Exception ignore) {}
2970+
}
29622971
}

src/core/lombok/eclipse/handlers/HandleBuilder.java

-9
Original file line numberDiff line numberDiff line change
@@ -1060,15 +1060,6 @@ private void makePrefixedSetterMethodForBuilder(BuilderJob job, BuilderFieldData
10601060
injectMethod(job.builderType, setter);
10611061
}
10621062

1063-
private void copyJavadocFromParam(EclipseNode from, MethodDeclaration to, TypeDeclaration type, String param) {
1064-
try {
1065-
CompilationUnitDeclaration cud = (CompilationUnitDeclaration) from.top().get();
1066-
String methodComment = getDocComment(from);
1067-
String newJavadoc = addReturnsThisIfNeeded(getParamJavadoc(methodComment, param));
1068-
setDocComment(cud, type, to, newJavadoc);
1069-
} catch (Exception ignore) {}
1070-
}
1071-
10721063
public void makeBuilderClass(BuilderJob job) {
10731064
TypeDeclaration parent = (TypeDeclaration) job.parentType.get();
10741065
TypeDeclaration builder = new TypeDeclaration(parent.compilationResult);

src/core/lombok/eclipse/handlers/HandleSuperBuilder.java

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import lombok.eclipse.Eclipse;
9292
import lombok.eclipse.EclipseAnnotationHandler;
9393
import lombok.eclipse.EclipseNode;
94+
import lombok.eclipse.handlers.EclipseHandlerUtil.CopyJavadoc;
9495
import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult;
9596
import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer;
9697
import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData;
@@ -1010,6 +1011,11 @@ private void generateSimpleSetterMethodForBuilder(BuilderJob job, boolean deprec
10101011
addCheckerFrameworkReturnsReceiver(returnType, job.source, job.checkerFramework);
10111012
MethodDeclaration setter = HandleSetter.createSetter(td, deprecate, fieldNode, setterName, paramName, nameOfSetFlag, returnType, returnStatement, ClassFileConstants.AccPublic,
10121013
job.sourceNode, methodAnnsList, annosOnParam != null ? Arrays.asList(copyAnnotations(job.source, annosOnParam)) : Collections.<Annotation>emptyList());
1014+
if (job.sourceNode.up().getKind() == Kind.METHOD) {
1015+
copyJavadocFromParam(originalFieldNode.up(), setter, td, paramName.toString());
1016+
} else {
1017+
copyJavadoc(originalFieldNode, setter, td, CopyJavadoc.SETTER, true);
1018+
}
10131019
injectMethod(job.builderType, setter);
10141020
}
10151021

src/core/lombok/javac/handlers/HandleBuilder.java

-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree;
3737
import com.sun.tools.javac.tree.JCTree.JCBlock;
3838
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
39-
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
4039
import com.sun.tools.javac.tree.JCTree.JCExpression;
4140
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
4241
import com.sun.tools.javac.tree.JCTree.JCIdent;
@@ -943,15 +942,6 @@ private void makePrefixedSetterMethodForBuilder(BuilderJob job, BuilderFieldData
943942
injectMethod(job.builderType, newMethod);
944943
}
945944

946-
private void copyJavadocFromParam(JavacNode from, JCMethodDecl to, String param) {
947-
try {
948-
JCCompilationUnit cu = ((JCCompilationUnit) from.top().get());
949-
String methodComment = Javac.getDocComment(cu, from.get());
950-
String newJavadoc = addReturnsThisIfNeeded(getParamJavadoc(methodComment, param));
951-
Javac.setDocComment(cu, to, newJavadoc);
952-
} catch (Exception ignore) {}
953-
}
954-
955945
public JavacNode makeBuilderClass(BuilderJob job) {
956946
//boolean isStatic, JavacNode source, JavacNode tdParent, String builderClassName, List<JCTypeParameter> typeParams, JCAnnotation ast, AccessLevel access) {
957947
//isStatic, annotationNode, tdParent, builderClassName, typeParams, ast, accessForOuters

src/core/lombok/javac/handlers/HandleSuperBuilder.java

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import lombok.javac.JavacTreeMaker;
7878
import lombok.javac.handlers.HandleBuilder.BuilderFieldData;
7979
import lombok.javac.handlers.HandleBuilder.BuilderJob;
80+
import lombok.javac.handlers.JavacHandlerUtil.CopyJavadoc;
8081
import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult;
8182
import lombok.javac.handlers.JavacSingularsRecipes.ExpressionMaker;
8283
import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer;
@@ -966,6 +967,11 @@ private void generateSimpleSetterMethodForBuilder(SuperBuilderJob job, boolean d
966967
returnType = addCheckerFrameworkReturnsReceiver(returnType, maker, job.builderType, job.checkerFramework);
967968

968969
JCMethodDecl newMethod = HandleSetter.createSetter(Flags.PUBLIC, deprecate, fieldNode, maker, setterName, paramName, nameOfSetFlag, returnType, returnStatement, job.sourceNode, methodAnns, annosOnParam);
970+
if (job.sourceNode.up().getKind() == Kind.METHOD) {
971+
copyJavadocFromParam(originalFieldNode.up(), newMethod, paramName.toString());
972+
} else {
973+
copyJavadoc(originalFieldNode, newMethod, CopyJavadoc.SETTER, true);
974+
}
969975
injectMethod(job.builderType, newMethod);
970976
}
971977

src/core/lombok/javac/handlers/JavacHandlerUtil.java

+9
Original file line numberDiff line numberDiff line change
@@ -2340,6 +2340,15 @@ public static void copyJavadoc(JavacNode from, JCTree to, CopyJavadoc copyMode,
23402340
} catch (Exception ignore) {}
23412341
}
23422342

2343+
public static void copyJavadocFromParam(JavacNode from, JCMethodDecl to, String paramName) {
2344+
try {
2345+
JCCompilationUnit cu = ((JCCompilationUnit) from.top().get());
2346+
String methodComment = Javac.getDocComment(cu, from.get());
2347+
String newJavadoc = addReturnsThisIfNeeded(getParamJavadoc(methodComment, paramName));
2348+
Javac.setDocComment(cu, to, newJavadoc);
2349+
} catch (Exception ignore) {}
2350+
}
2351+
23432352
public static boolean isDirectDescendantOfObject(JavacNode typeNode) {
23442353
if (!(typeNode.get() instanceof JCClassDecl)) throw new IllegalArgumentException("not a type node");
23452354
JCTree extending = Javac.getExtendsClause((JCClassDecl) typeNode.get());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import java.util.List;
2+
3+
public abstract class SuperBuilderJavadoc {
4+
/**
5+
* basic gets only a builder setter.
6+
* @see #getsetwith
7+
* @return tag is removed from the setter.
8+
*/
9+
private final int basic;
10+
/**
11+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
12+
*/
13+
private int getsetwith;
14+
/**
15+
* Predef has a predefined builder setter with no javadoc, and the builder setter does not get this one.
16+
* @param tag remains on the field.
17+
* @return tag remains on the field.
18+
*/
19+
private final int predef;
20+
/**
21+
* predefWithJavadoc has a predefined builder setter with javadoc, so it keeps that one untouched.
22+
* @param tag is removed from the field.
23+
* @return tag remains on the field.
24+
*/
25+
private final int predefWithJavadoc;
26+
27+
28+
public static abstract class SuperBuilderJavadocBuilder<C extends SuperBuilderJavadoc, B extends SuperBuilderJavadocBuilder<C, B>> {
29+
@java.lang.SuppressWarnings("all")
30+
private int basic;
31+
@java.lang.SuppressWarnings("all")
32+
private int getsetwith;
33+
@java.lang.SuppressWarnings("all")
34+
private int predef;
35+
@java.lang.SuppressWarnings("all")
36+
private int predefWithJavadoc;
37+
38+
public B predef(final int x) {
39+
this.predef = x * 10;
40+
return self();
41+
}
42+
43+
/**
44+
* This javadoc remains untouched.
45+
* @param x 1/100 of the thing
46+
* @return the updated builder
47+
*/
48+
public B predefWithJavadoc(final int x) {
49+
this.predefWithJavadoc = x * 100;
50+
return self();
51+
}
52+
53+
/**
54+
* basic gets only a builder setter.
55+
* @see #getsetwith
56+
* @param tag is moved to the setter.
57+
* @return {@code this}.
58+
*/
59+
@java.lang.SuppressWarnings("all")
60+
public B basic(final int basic) {
61+
this.basic = basic;
62+
return self();
63+
}
64+
65+
/**
66+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
67+
* @param tag is moved to the setters and wither.
68+
* @return {@code this}.
69+
*/
70+
@java.lang.SuppressWarnings("all")
71+
public B getsetwith(final int getsetwith) {
72+
this.getsetwith = getsetwith;
73+
return self();
74+
}
75+
76+
@java.lang.SuppressWarnings("all")
77+
protected abstract B self();
78+
79+
@java.lang.SuppressWarnings("all")
80+
public abstract C build();
81+
82+
@java.lang.Override
83+
@java.lang.SuppressWarnings("all")
84+
public java.lang.String toString() {
85+
return "SuperBuilderJavadoc.SuperBuilderJavadocBuilder(basic=" + this.basic + ", getsetwith=" + this.getsetwith + ", predef=" + this.predef + ", predefWithJavadoc=" + this.predefWithJavadoc + ")";
86+
}
87+
}
88+
89+
@java.lang.SuppressWarnings("all")
90+
protected SuperBuilderJavadoc(final SuperBuilderJavadoc.SuperBuilderJavadocBuilder<?, ?> b) {
91+
this.basic = b.basic;
92+
this.getsetwith = b.getsetwith;
93+
this.predef = b.predef;
94+
this.predefWithJavadoc = b.predefWithJavadoc;
95+
}
96+
97+
/**
98+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
99+
* @return tag is moved to the getter.
100+
*/
101+
@java.lang.SuppressWarnings("all")
102+
public int getGetsetwith() {
103+
return this.getsetwith;
104+
}
105+
106+
/**
107+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
108+
* @param tag is moved to the setters and wither.
109+
*/
110+
@java.lang.SuppressWarnings("all")
111+
public void setGetsetwith(final int getsetwith) {
112+
this.getsetwith = getsetwith;
113+
}
114+
115+
/**
116+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
117+
* @param tag is moved to the setters and wither.
118+
* @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed).
119+
*/
120+
@java.lang.SuppressWarnings("all")
121+
public abstract SuperBuilderJavadoc withGetsetwith(final int getsetwith);
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import java.util.List;
2+
public abstract @lombok.experimental.SuperBuilder class SuperBuilderJavadoc {
3+
public static abstract class SuperBuilderJavadocBuilder<C extends SuperBuilderJavadoc, B extends SuperBuilderJavadocBuilder<C, B>> {
4+
private @java.lang.SuppressWarnings("all") int basic;
5+
private @java.lang.SuppressWarnings("all") int getsetwith;
6+
private @java.lang.SuppressWarnings("all") int predef;
7+
private @java.lang.SuppressWarnings("all") int predefWithJavadoc;
8+
public SuperBuilderJavadocBuilder() {
9+
super();
10+
}
11+
public B predef(final int x) {
12+
this.predef = (x * 10);
13+
return self();
14+
}
15+
public B predefWithJavadoc(final int x) {
16+
this.predefWithJavadoc = (x * 100);
17+
return self();
18+
}
19+
/**
20+
* basic gets only a builder setter.
21+
* @see #getsetwith
22+
* @param tag is moved to the setter.
23+
* @return {@code this}.
24+
*/
25+
public @java.lang.SuppressWarnings("all") B basic(final int basic) {
26+
this.basic = basic;
27+
return self();
28+
}
29+
/**
30+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
31+
* @param tag is moved to the setters and wither.
32+
* @return {@code this}.
33+
*/
34+
public @java.lang.SuppressWarnings("all") B getsetwith(final int getsetwith) {
35+
this.getsetwith = getsetwith;
36+
return self();
37+
}
38+
protected abstract @java.lang.SuppressWarnings("all") B self();
39+
public abstract @java.lang.SuppressWarnings("all") C build();
40+
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
41+
return (((((((("SuperBuilderJavadoc.SuperBuilderJavadocBuilder(basic=" + this.basic) + ", getsetwith=") + this.getsetwith) + ", predef=") + this.predef) + ", predefWithJavadoc=") + this.predefWithJavadoc) + ")");
42+
}
43+
}
44+
private final int basic;
45+
private @lombok.Getter @lombok.Setter @lombok.experimental.Wither int getsetwith;
46+
private final int predef;
47+
private final int predefWithJavadoc;
48+
protected @java.lang.SuppressWarnings("all") SuperBuilderJavadoc(final SuperBuilderJavadoc.SuperBuilderJavadocBuilder<?, ?> b) {
49+
super();
50+
this.basic = b.basic;
51+
this.getsetwith = b.getsetwith;
52+
this.predef = b.predef;
53+
this.predefWithJavadoc = b.predefWithJavadoc;
54+
}
55+
/**
56+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
57+
* @return tag is moved to the getter.
58+
*/
59+
public @java.lang.SuppressWarnings("all") int getGetsetwith() {
60+
return this.getsetwith;
61+
}
62+
/**
63+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
64+
* @param tag is moved to the setters and wither.
65+
*/
66+
public @java.lang.SuppressWarnings("all") void setGetsetwith(final int getsetwith) {
67+
this.getsetwith = getsetwith;
68+
}
69+
/**
70+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
71+
* @param tag is moved to the setters and wither.
72+
* @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed).
73+
*/
74+
public abstract @java.lang.SuppressWarnings("all") SuperBuilderJavadoc withGetsetwith(final int getsetwith);
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.util.List;
2+
3+
@lombok.experimental.SuperBuilder
4+
public abstract class SuperBuilderJavadoc {
5+
/**
6+
* basic gets only a builder setter.
7+
* @see #getsetwith
8+
* @param tag is moved to the setter.
9+
* @return tag is removed from the setter.
10+
*/
11+
private final int basic;
12+
13+
/**
14+
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
15+
* @param tag is moved to the setters and wither.
16+
* @return tag is moved to the getter.
17+
*/
18+
@lombok.Getter
19+
@lombok.Setter
20+
@lombok.experimental.Wither
21+
private int getsetwith;
22+
23+
/**
24+
* Predef has a predefined builder setter with no javadoc, and the builder setter does not get this one.
25+
* @param tag remains on the field.
26+
* @return tag remains on the field.
27+
*/
28+
private final int predef;
29+
30+
/**
31+
* predefWithJavadoc has a predefined builder setter with javadoc, so it keeps that one untouched.
32+
* @param tag is removed from the field.
33+
* @return tag remains on the field.
34+
*/
35+
private final int predefWithJavadoc;
36+
37+
public static abstract class SuperBuilderJavadocBuilder<C extends SuperBuilderJavadoc, B extends SuperBuilderJavadocBuilder<C, B>> {
38+
public B predef(final int x) {
39+
this.predef = x * 10;
40+
return self();
41+
}
42+
43+
/**
44+
* This javadoc remains untouched.
45+
* @param x 1/100 of the thing
46+
* @return the updated builder
47+
*/
48+
public B predefWithJavadoc(final int x) {
49+
this.predefWithJavadoc = x * 100;
50+
return self();
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)