Copy Javadoc to @Builder setters

This commit is contained in:
Emil Lundberg authored and Roel Spilker committed 2019-01-15 00:00:19 +01:00
1 parent 81c477c43d
commit 1ad1a94143
6 files changed
+274 -4

No files matched your search

@@ -701,13 +701,13 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
public void makeSetterMethodsForBuilder(JavacNode builderType, BuilderFieldData fieldNode, JavacNode source, boolean fluent, boolean chain) {
boolean deprecate = isFieldDeprecated(fieldNode.originalFieldNode);
if (fieldNode.singularData == null || fieldNode.singularData.getSingularizer() == null) {
makeSimpleSetterMethodForBuilder(builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.nameOfSetFlag, source, fluent, chain, fieldNode.annotations);
makeSimpleSetterMethodForBuilder(builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.nameOfSetFlag, source, fluent, chain, fieldNode.annotations, fieldNode.originalFieldNode);
} else {
fieldNode.singularData.getSingularizer().generateMethods(fieldNode.singularData, deprecate, builderType, source.get(), fluent, chain);
}
}
private void makeSimpleSetterMethodForBuilder(JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name nameOfSetFlag, JavacNode source, boolean fluent, boolean chain, List<JCAnnotation> annosOnParam) {
private void makeSimpleSetterMethodForBuilder(JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name nameOfSetFlag, JavacNode source, boolean fluent, boolean chain, List<JCAnnotation> annosOnParam, JavacNode originalFieldNode) {
Name fieldName = ((JCVariableDecl) fieldNode.get()).name;
for (JavacNode child : builderType.down()) {
@@ -723,6 +723,8 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
JCMethodDecl newMethod = HandleSetter.createSetter(Flags.PUBLIC, deprecate, fieldNode, maker, setterName, nameOfSetFlag, chain, source, List.<JCAnnotation>nil(), annosOnParam);
recursiveSetGeneratedBy(newMethod, source.get(), builderType.getContext());
copyJavadoc(originalFieldNode, newMethod, CopyJavadoc.SETTER);
injectMethod(builderType, newMethod);
}
@@ -0,0 +1,133 @@
import java.util.List;
class BuilderJavadoc<T> {
/**
* Will not get a setter on the builder.
*/
private final int noshow = 0;
/**
* Yes, yes gets a setter.
* @see #also
*
* @return tag is removed from the setter.
*/
private final int yes;
/**
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
*/
private int getsetwith;
/**
* Predef has a predefined builder setter with no javadoc, and the builder setter does not get this one.
* @param tag remains on the field.
* @return tag remains on the field.
*/
private final int predef;
/**
* predefWithJavadoc has a predefined builder setter with javadoc, so it keeps that one untouched.
* @param tag is removed from the field.
* @return tag remains on the field.
*/
private final int predefWithJavadoc;
private List<T> also;
/**
* But this one doesn't.
*/
private int $butNotMe;
public static class BuilderJavadocBuilder<T> {
@java.lang.SuppressWarnings("all")
private int yes;
@java.lang.SuppressWarnings("all")
private int getsetwith;
@java.lang.SuppressWarnings("all")
private int predef;
@java.lang.SuppressWarnings("all")
private int predefWithJavadoc;
@java.lang.SuppressWarnings("all")
private List<T> also;
public BuilderJavadocBuilder<T> predef(final int x) {
this.predef = x * 10;
return this;
}
/**
* This javadoc remains untouched.
* @param x 1/100 of the thing
* @return the updated builder
*/
public BuilderJavadocBuilder<T> predefWithJavadoc(final int x) {
this.predefWithJavadoc = x * 100;
return this;
}
@java.lang.SuppressWarnings("all")
BuilderJavadocBuilder() {
}
/**
* Yes, yes gets a setter.
* @see #also
* @param tag is moved to the setter.
*/
@java.lang.SuppressWarnings("all")
public BuilderJavadocBuilder<T> yes(final int yes) {
this.yes = yes;
return this;
}
/**
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
* @param tag is moved to the setters and wither.
*/
@java.lang.SuppressWarnings("all")
public BuilderJavadocBuilder<T> getsetwith(final int getsetwith) {
this.getsetwith = getsetwith;
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderJavadocBuilder<T> also(final List<T> also) {
this.also = also;
return this;
}
@java.lang.SuppressWarnings("all")
public BuilderJavadoc<T> build() {
return new BuilderJavadoc<T>(yes, getsetwith, predef, predefWithJavadoc, also);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "BuilderJavadoc.BuilderJavadocBuilder(yes=" + this.yes + ", getsetwith=" + this.getsetwith + ", predef=" + this.predef + ", predefWithJavadoc=" + this.predefWithJavadoc + ", also=" + this.also + ")";
}
}
@java.lang.SuppressWarnings("all")
BuilderJavadoc(final int yes, final int getsetwith, final int predef, final int predefWithJavadoc, final List<T> also) {
this.yes = yes;
this.getsetwith = getsetwith;
this.predef = predef;
this.predefWithJavadoc = predefWithJavadoc;
this.also = also;
}
@java.lang.SuppressWarnings("all")
public static <T> BuilderJavadocBuilder<T> builder() {
return new BuilderJavadocBuilder<T>();
}
/**
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
*
* @return tag is moved to the getter.
*/
@java.lang.SuppressWarnings("all")
public int getGetsetwith() {
return this.getsetwith;
}
/**
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
* @param tag is moved to the setters and wither.
*/
@java.lang.SuppressWarnings("all")
public void setGetsetwith(final int getsetwith) {
this.getsetwith = getsetwith;
}
/**
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
* @param tag is moved to the setters and wither.
*/
@java.lang.SuppressWarnings("all")
public BuilderJavadoc<T> withGetsetwith(final int getsetwith) {
return this.getsetwith == getsetwith ? this : new BuilderJavadoc<T>(this.yes, getsetwith, this.predef, this.predefWithJavadoc, this.also);
}
}
@@ -1,7 +1,7 @@
import com.google.common.collect.ImmutableList;
public class BuilderWithDeprecated {
/**
* @deprecated
* @deprecated since always
*/
String dep1;
@Deprecated
@@ -30,6 +30,9 @@ public class BuilderWithDeprecated {
@java.lang.SuppressWarnings("all")
BuilderWithDeprecatedBuilder() {
}
/**
* @deprecated since always
*/
@java.lang.Deprecated
@java.lang.SuppressWarnings("all")
public BuilderWithDeprecatedBuilder dep1(final String dep1) {
@@ -0,0 +1,66 @@
import java.util.List;
@lombok.Builder class BuilderJavadoc<T> {
public static class BuilderJavadocBuilder<T> {
private @java.lang.SuppressWarnings("all") int yes;
private @java.lang.SuppressWarnings("all") int getsetwith;
private @java.lang.SuppressWarnings("all") int predef;
private @java.lang.SuppressWarnings("all") int predefWithJavadoc;
private @java.lang.SuppressWarnings("all") List<T> also;
public BuilderJavadocBuilder<T> predef(final int x) {
this.predef = (x * 10);
return this;
}
public BuilderJavadocBuilder<T> predefWithJavadoc(final int x) {
this.predefWithJavadoc = (x * 100);
return this;
}
@java.lang.SuppressWarnings("all") BuilderJavadocBuilder() {
super();
}
public @java.lang.SuppressWarnings("all") BuilderJavadocBuilder<T> yes(final int yes) {
this.yes = yes;
return this;
}
public @java.lang.SuppressWarnings("all") BuilderJavadocBuilder<T> getsetwith(final int getsetwith) {
this.getsetwith = getsetwith;
return this;
}
public @java.lang.SuppressWarnings("all") BuilderJavadocBuilder<T> also(final List<T> also) {
this.also = also;
return this;
}
public @java.lang.SuppressWarnings("all") BuilderJavadoc<T> build() {
return new BuilderJavadoc<T>(yes, getsetwith, predef, predefWithJavadoc, also);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
return (((((((((("BuilderJavadoc.BuilderJavadocBuilder(yes=" + this.yes) + ", getsetwith=") + this.getsetwith) + ", predef=") + this.predef) + ", predefWithJavadoc=") + this.predefWithJavadoc) + ", also=") + this.also) + ")");
}
}
private final int noshow = 0;
private final int yes;
private @lombok.Getter @lombok.Setter @lombok.experimental.Wither int getsetwith;
private final int predef;
private final int predefWithJavadoc;
private List<T> also;
private int $butNotMe;
@java.lang.SuppressWarnings("all") BuilderJavadoc(final int yes, final int getsetwith, final int predef, final int predefWithJavadoc, final List<T> also) {
super();
this.yes = yes;
this.getsetwith = getsetwith;
this.predef = predef;
this.predefWithJavadoc = predefWithJavadoc;
this.also = also;
}
public static @java.lang.SuppressWarnings("all") <T>BuilderJavadocBuilder<T> builder() {
return new BuilderJavadocBuilder<T>();
}
public @java.lang.SuppressWarnings("all") int getGetsetwith() {
return this.getsetwith;
}
public @java.lang.SuppressWarnings("all") void setGetsetwith(final int getsetwith) {
this.getsetwith = getsetwith;
}
public @java.lang.SuppressWarnings("all") BuilderJavadoc<T> withGetsetwith(final int getsetwith) {
return ((this.getsetwith == getsetwith) ? this : new BuilderJavadoc<T>(this.yes, getsetwith, this.predef, this.predefWithJavadoc, this.also));
}
}
@@ -0,0 +1,66 @@
import java.util.List;
@lombok.Builder
class BuilderJavadoc<T> {
/**
* Will not get a setter on the builder.
*/
private final int noshow = 0;
/**
* Yes, yes gets a setter.
* @see #also
* @param tag is moved to the setter.
* @return tag is removed from the setter.
*/
private final int yes;
/**
* getsetwith gets a builder setter, an instance getter and setter, and a wither.
* @param tag is moved to the setters and wither.
* @return tag is moved to the getter.
*/
@lombok.Getter
@lombok.Setter
@lombok.experimental.Wither
private int getsetwith;
/**
* Predef has a predefined builder setter with no javadoc, and the builder setter does not get this one.
* @param tag remains on the field.
* @return tag remains on the field.
*/
private final int predef;
/**
* predefWithJavadoc has a predefined builder setter with javadoc, so it keeps that one untouched.
* @param tag is removed from the field.
* @return tag remains on the field.
*/
private final int predefWithJavadoc;
private List<T> also;
/**
* But this one doesn't.
*/
private int $butNotMe;
public static class BuilderJavadocBuilder<T> {
public BuilderJavadocBuilder<T> predef(final int x) {
this.predef = x * 10;
return this;
}
/**
* This javadoc remains untouched.
* @param x 1/100 of the thing
* @return the updated builder
*/
public BuilderJavadocBuilder<T> predefWithJavadoc(final int x) {
this.predefWithJavadoc = x * 100;
return this;
}
}
}
@@ -4,7 +4,7 @@ import lombok.Singular;
@Builder
public class BuilderWithDeprecated {
/** @deprecated */ String dep1;
/** @deprecated since always */ String dep1;
@Deprecated int dep2;
@Singular @Deprecated java.util.List<String> strings;
@Singular @Deprecated ImmutableList<Integer> numbers;