aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Lundberg <emil@yubico.com>2019-01-08 12:37:14 +0100
committerRoel Spilker <r.spilker@gmail.com>2019-01-15 00:00:19 +0100
commit1ad1a941430af5b6662946d6591c9756d0178cb2 (patch)
treec97acc5ae5aa63fbd7b9cc687a4591e1de41dc0b
parent81c477c43dc8e52d6a40d6533b3d716f0b617e6e (diff)
downloadlombok-1ad1a941430af5b6662946d6591c9756d0178cb2.tar.gz
lombok-1ad1a941430af5b6662946d6591c9756d0178cb2.tar.bz2
lombok-1ad1a941430af5b6662946d6591c9756d0178cb2.zip
Copy Javadoc to @Builder setters
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java6
-rw-r--r--test/transform/resource/after-delombok/BuilderJavadoc.java133
-rw-r--r--test/transform/resource/after-delombok/BuilderWithDeprecated.java5
-rw-r--r--test/transform/resource/after-ecj/BuilderJavadoc.java66
-rw-r--r--test/transform/resource/before/BuilderJavadoc.java66
-rw-r--r--test/transform/resource/before/BuilderWithDeprecated.java2
6 files changed, 274 insertions, 4 deletions
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index 83a44cca..081123aa 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -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);
}
diff --git a/test/transform/resource/after-delombok/BuilderJavadoc.java b/test/transform/resource/after-delombok/BuilderJavadoc.java
new file mode 100644
index 00000000..e33602c5
--- /dev/null
+++ b/test/transform/resource/after-delombok/BuilderJavadoc.java
@@ -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);
+ }
+}
diff --git a/test/transform/resource/after-delombok/BuilderWithDeprecated.java b/test/transform/resource/after-delombok/BuilderWithDeprecated.java
index cd887529..f06a11f2 100644
--- a/test/transform/resource/after-delombok/BuilderWithDeprecated.java
+++ b/test/transform/resource/after-delombok/BuilderWithDeprecated.java
@@ -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) {
diff --git a/test/transform/resource/after-ecj/BuilderJavadoc.java b/test/transform/resource/after-ecj/BuilderJavadoc.java
new file mode 100644
index 00000000..8cc487eb
--- /dev/null
+++ b/test/transform/resource/after-ecj/BuilderJavadoc.java
@@ -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));
+ }
+}
diff --git a/test/transform/resource/before/BuilderJavadoc.java b/test/transform/resource/before/BuilderJavadoc.java
new file mode 100644
index 00000000..93b8bedf
--- /dev/null
+++ b/test/transform/resource/before/BuilderJavadoc.java
@@ -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;
+ }
+ }
+
+}
diff --git a/test/transform/resource/before/BuilderWithDeprecated.java b/test/transform/resource/before/BuilderWithDeprecated.java
index cd8ffad9..1641ccb4 100644
--- a/test/transform/resource/before/BuilderWithDeprecated.java
+++ b/test/transform/resource/before/BuilderWithDeprecated.java
@@ -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;