From e1c39bbc601408decb0ae147d181708a5af41307 Mon Sep 17 00:00:00 2001
From: Reinier Zwitserloot
Date: Tue, 18 Jun 2013 04:23:15 +0200
Subject: javac builder implementation. Passes all tests. Added toString() impl
for builders in both eclipse and javac. Added all documentation, though it'll
need some reviewing.
---
.../experimental/BuilderExample_post.jpage | 40 ++++++++++++++++++++++
.../experimental/BuilderExample_pre.jpage | 7 ++++
2 files changed, 47 insertions(+)
create mode 100644 usage_examples/experimental/BuilderExample_post.jpage
create mode 100644 usage_examples/experimental/BuilderExample_pre.jpage
(limited to 'usage_examples/experimental')
diff --git a/usage_examples/experimental/BuilderExample_post.jpage b/usage_examples/experimental/BuilderExample_post.jpage
new file mode 100644
index 00000000..624b236b
--- /dev/null
+++ b/usage_examples/experimental/BuilderExample_post.jpage
@@ -0,0 +1,40 @@
+public class BuilderExample {
+ private String name;
+ private int age;
+
+ BuilderExample(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public static BuilderExampleBuilder builder() {
+ return new BuilderExampleBuilder();
+ }
+
+ public static class BuilderExampleBuilder {
+ private String name;
+ private int age;
+
+ BuilderExampleBuilder() {
+ }
+
+ public BuilderExampleBuilder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public BuilderExampleBuilder age(int age) {
+ this.age = age;
+ return this;
+ }
+
+ public BuilderExample build() {
+ return new BuilderExample(name, age);
+ }
+
+ @java.lang.Override
+ public String toString() {
+ return "BuilderExample.BuilderExampleBuilder(name = " + this.name + ", age = " + this.age + ")";
+ }
+ }
+}
\ No newline at end of file
diff --git a/usage_examples/experimental/BuilderExample_pre.jpage b/usage_examples/experimental/BuilderExample_pre.jpage
new file mode 100644
index 00000000..9c754352
--- /dev/null
+++ b/usage_examples/experimental/BuilderExample_pre.jpage
@@ -0,0 +1,7 @@
+import lombok.experimental.Builder;
+
+@Builder
+public class BuilderExample {
+ private String name;
+ private int age;
+}
--
cgit
From e7ff097fec867714b8a064b559dfc9e5162a489c Mon Sep 17 00:00:00 2001
From: Reinier Zwitserloot
Date: Mon, 8 Jul 2013 21:17:01 +0200
Subject: Fixed value's snippet integration (it hadn't been updated yet now
that Value has moved from experimental into core).
---
buildScripts/website.ant.xml | 6 +-
doc/changelog.markdown | 2 +-
src/core/lombok/javac/handlers/HandleWither.java | 5 +-
.../lombok/javac/handlers/JavacHandlerUtil.java | 27 +++--
.../resource/after-delombok/WitherDeprecated.java | 3 +
usage_examples/ValueExample_post.jpage | 120 +++++++++++++++++++++
usage_examples/ValueExample_pre.jpage | 19 ++++
.../experimental/ValueExample_post.jpage | 120 ---------------------
usage_examples/experimental/ValueExample_pre.jpage | 19 ----
website/features/experimental/Wither.html | 2 +
10 files changed, 170 insertions(+), 153 deletions(-)
create mode 100644 usage_examples/ValueExample_post.jpage
create mode 100644 usage_examples/ValueExample_pre.jpage
delete mode 100644 usage_examples/experimental/ValueExample_post.jpage
delete mode 100644 usage_examples/experimental/ValueExample_pre.jpage
(limited to 'usage_examples/experimental')
diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml
index 521ca59b..baf869a4 100644
--- a/buildScripts/website.ant.xml
+++ b/buildScripts/website.ant.xml
@@ -142,6 +142,9 @@ such as converting the changelog into HTML, and creating javadoc.
+
+
+
@@ -163,9 +166,6 @@ such as converting the changelog into HTML, and creating javadoc.
-
-
-
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index 75825d77..d15e24be 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -2,7 +2,7 @@ Lombok Changelog
----------------
### v0.11.9 (Edgy Guinea Pig)
-* FEATURE: javadoc on fields will now be copied to generated getters / setters. There are ways to specify separate javadoc for the field, the setter, and the getter, and `@param` and `@return` are handled appropriately. Addresses feature request [Issue #59](https://code.google.com/p/projectlombok/issues/detail?id=59). [@Getter and @Setter documentation](http://projectlombok.org/features/GetterSetter.html).
+* FEATURE: javadoc on fields will now be copied to generated getters / setters / withers. There are ways to specify separate javadoc for the field, the setter, and the getter, and `@param` and `@return` are handled appropriately. Addresses feature request [Issue #59](https://code.google.com/p/projectlombok/issues/detail?id=59). [@Getter and @Setter documentation](http://projectlombok.org/features/GetterSetter.html). [@Wither documentation](http://projectlombok.org/features/experimental/Wither.html).
* CHANGE: The desugaring of @Getter(lazy=true) is now less object creation intensive. Documentation has been updated to reflect what the new desugaring looks like. [@Getter(lazy=true) documentation](http://projectlombok.org/features/GetterLazy.html).
* PROMOTION: `@Value` has been promoted from experimental to the main package with no changes. The 'old' experimental one is still around but is deprecated, and is an alias for the new main package one. [@Value documentation](http://projectlombok.org/features/Value.html).
* FEATURE: {Experimental} `@Builder` support. One of our earliest feature request issues, [Issue #16](https://code.google.com/p/projectlombok/issues/detail?id=16), has finally been addressed. [@Builder documentation](http://projectlombok.org/features/experimental/Builder.html).
diff --git a/src/core/lombok/javac/handlers/HandleWither.java b/src/core/lombok/javac/handlers/HandleWither.java
index ba5aa72d..b3f218b8 100644
--- a/src/core/lombok/javac/handlers/HandleWither.java
+++ b/src/core/lombok/javac/handlers/HandleWither.java
@@ -33,6 +33,7 @@ import lombok.core.TransformationsUtil;
import lombok.experimental.Wither;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
+import lombok.javac.handlers.JavacHandlerUtil.CopyJavadoc;
import lombok.javac.handlers.JavacHandlerUtil.FieldAccess;
import org.mangosdk.spi.ProviderFor;
@@ -264,7 +265,9 @@ public class HandleWither extends JavacAnnotationHandler {
if (isFieldDeprecated(field)) {
annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(chainDots(field, "java", "lang", "Deprecated"), List.nil()));
}
- return recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, returnType,
+ JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, returnType,
methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source);
+ copyJavadoc(field, decl, CopyJavadoc.WITHER);
+ return decl;
}
}
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 6aed5508..a24dad7d 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -1165,7 +1165,7 @@ public class JavacHandlerUtil {
return (JCExpression) in;
}
- private static final Pattern SECTION_FINDER = Pattern.compile("^\\s*\\**\\s*[-*][-*]+\\s*([GS]ETTER)\\s*[-*][-*]+\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
+ private static final Pattern SECTION_FINDER = Pattern.compile("^\\s*\\**\\s*[-*][-*]+\\s*([GS]ETTER|WITHER)\\s*[-*][-*]+\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
private static String stripLinesWithTagFromJavadoc(String javadoc, String regexpFragment) {
Pattern p = Pattern.compile("^\\s*\\**\\s*" + regexpFragment + "\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
@@ -1213,17 +1213,26 @@ public class JavacHandlerUtil {
},
SETTER {
@Override public String[] split(String javadoc) {
- // step 1: Check if there is a 'SETTER' section. If yes, that becomes the new one and we strip that from the original.
- String[] out = splitJavadocOnSectionIfPresent(javadoc, "SETTER");
- if (out != null) return out;
- // failing that, create a copy, but strip @param from the original and @return from the copy.
- String copy = javadoc;
- javadoc = stripLinesWithTagFromJavadoc(javadoc, "@param(?:eter)?\\s+.*");
- copy = stripLinesWithTagFromJavadoc(copy, "@returns?\\s+.*");
- return new String[] {copy, javadoc};
+ return splitForSetters(javadoc, "SETTER");
+ }
+ },
+ WITHER {
+ @Override public String[] split(String javadoc) {
+ return splitForSetters(javadoc, "WITHER");
}
};
+ private static String[] splitForSetters(String javadoc, String sectionName) {
+ // step 1: Check if there is a 'SETTER' section. If yes, that becomes the new one and we strip that from the original.
+ String[] out = splitJavadocOnSectionIfPresent(javadoc, sectionName);
+ if (out != null) return out;
+ // failing that, create a copy, but strip @param from the original and @return from the copy.
+ String copy = javadoc;
+ javadoc = stripLinesWithTagFromJavadoc(javadoc, "@param(?:eter)?\\s+.*");
+ copy = stripLinesWithTagFromJavadoc(copy, "@returns?\\s+.*");
+ return new String[] {copy, javadoc};
+ }
+
/** Splits the javadoc into the section to be copied (ret[0]) and the section to replace the original with (ret[1]) */
public String[] split(String javadoc) {
return new String[] {javadoc, javadoc};
diff --git a/test/transform/resource/after-delombok/WitherDeprecated.java b/test/transform/resource/after-delombok/WitherDeprecated.java
index f076d90e..29192012 100644
--- a/test/transform/resource/after-delombok/WitherDeprecated.java
+++ b/test/transform/resource/after-delombok/WitherDeprecated.java
@@ -12,6 +12,9 @@ class WitherDeprecated {
public WitherDeprecated withAnnotation(final int annotation) {
return this.annotation == annotation ? this : new WitherDeprecated(annotation, this.javadoc);
}
+ /**
+ * @deprecated
+ */
@java.lang.Deprecated
@java.lang.SuppressWarnings("all")
public WitherDeprecated withJavadoc(final int javadoc) {
diff --git a/usage_examples/ValueExample_post.jpage b/usage_examples/ValueExample_post.jpage
new file mode 100644
index 00000000..ac9b64d1
--- /dev/null
+++ b/usage_examples/ValueExample_post.jpage
@@ -0,0 +1,120 @@
+import java.util.Arrays;
+
+public final class ValueExample {
+ private final String name;
+ private int age;
+ private final double score;
+ protected final String[] tags;
+
+ @java.beans.ConstructorProperties({"name", "age", "score", "tags"})
+ public ValueExample(String name, int age, double score, String[] tags) {
+ this.name = name;
+ this.age = age;
+ this.score = score;
+ this.tags = tags;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public int getAge() {
+ return this.age;
+ }
+
+ public double getScore() {
+ return this.score;
+ }
+
+ public String[] getTags() {
+ return this.tags;
+ }
+
+ @java.lang.Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof ValueExample)) return false;
+ final ValueExample other = (ValueExample)o;
+ final Object this$name = this.getName();
+ final Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
+ if (this.getAge() != other.getAge()) return false;
+ if (Double.compare(this.getScore(), other.getScore()) != 0) return false;
+ if (!Arrays.deepEquals(this.getTags(), other.getTags())) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ final Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 0 : $name.hashCode());
+ result = result * PRIME + this.getAge();
+ final long $score = Double.doubleToLongBits(this.getScore());
+ result = result * PRIME + (int)($score >>> 32 ^ $score);
+ result = result * PRIME + Arrays.deepHashCode(this.getTags());
+ return result;
+ }
+
+ @java.lang.Override
+ public String toString() {
+ return "ValueExample(name=" + getName() + ", age=" + getAge() + ", score=" + getScore() + ", tags=" + Arrays.deepToString(getTags()) + ")";
+ }
+
+ ValueExample withAge(int age) {
+ return this.age == age ? this : new ValueExample(name, age, score, tags);
+ }
+
+ public static final class Exercise {
+ private final String name;
+ private final T value;
+
+ private Exercise(String name, T value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public static Exercise of(String name, T value) {
+ return new Exercise(name, value);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public T getValue() {
+ return this.value;
+ }
+
+ @java.lang.Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof ValueExample.Exercise)) return false;
+ final Exercise> other = (Exercise>)o;
+ final Object this$name = this.getName();
+ final Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
+ final Object this$value = this.getValue();
+ final Object other$value = other.getValue();
+ if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ final Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 0 : $name.hashCode());
+ final Object $value = this.getValue();
+ result = result * PRIME + ($value == null ? 0 : $value.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public String toString() {
+ return "ValueExample.Exercise(name=" + getName() + ", value=" + getValue() + ")";
+ }
+ }
+}
\ No newline at end of file
diff --git a/usage_examples/ValueExample_pre.jpage b/usage_examples/ValueExample_pre.jpage
new file mode 100644
index 00000000..d9550c25
--- /dev/null
+++ b/usage_examples/ValueExample_pre.jpage
@@ -0,0 +1,19 @@
+import lombok.AccessLevel;
+import lombok.experimental.NonFinal;
+import lombok.experimental.Value;
+import lombok.experimental.Wither;
+import lombok.ToString;
+
+@Value public class ValueExample {
+ String name;
+ @Wither(AccessLevel.PACKAGE) @NonFinal int age;
+ double score;
+ protected String[] tags;
+
+ @ToString(includeFieldNames=true)
+ @Value(staticConstructor="of")
+ public static class Exercise {
+ String name;
+ T value;
+ }
+}
diff --git a/usage_examples/experimental/ValueExample_post.jpage b/usage_examples/experimental/ValueExample_post.jpage
deleted file mode 100644
index ac9b64d1..00000000
--- a/usage_examples/experimental/ValueExample_post.jpage
+++ /dev/null
@@ -1,120 +0,0 @@
-import java.util.Arrays;
-
-public final class ValueExample {
- private final String name;
- private int age;
- private final double score;
- protected final String[] tags;
-
- @java.beans.ConstructorProperties({"name", "age", "score", "tags"})
- public ValueExample(String name, int age, double score, String[] tags) {
- this.name = name;
- this.age = age;
- this.score = score;
- this.tags = tags;
- }
-
- public String getName() {
- return this.name;
- }
-
- public int getAge() {
- return this.age;
- }
-
- public double getScore() {
- return this.score;
- }
-
- public String[] getTags() {
- return this.tags;
- }
-
- @java.lang.Override
- public boolean equals(Object o) {
- if (o == this) return true;
- if (!(o instanceof ValueExample)) return false;
- final ValueExample other = (ValueExample)o;
- final Object this$name = this.getName();
- final Object other$name = other.getName();
- if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
- if (this.getAge() != other.getAge()) return false;
- if (Double.compare(this.getScore(), other.getScore()) != 0) return false;
- if (!Arrays.deepEquals(this.getTags(), other.getTags())) return false;
- return true;
- }
-
- @java.lang.Override
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- final Object $name = this.getName();
- result = result * PRIME + ($name == null ? 0 : $name.hashCode());
- result = result * PRIME + this.getAge();
- final long $score = Double.doubleToLongBits(this.getScore());
- result = result * PRIME + (int)($score >>> 32 ^ $score);
- result = result * PRIME + Arrays.deepHashCode(this.getTags());
- return result;
- }
-
- @java.lang.Override
- public String toString() {
- return "ValueExample(name=" + getName() + ", age=" + getAge() + ", score=" + getScore() + ", tags=" + Arrays.deepToString(getTags()) + ")";
- }
-
- ValueExample withAge(int age) {
- return this.age == age ? this : new ValueExample(name, age, score, tags);
- }
-
- public static final class Exercise {
- private final String name;
- private final T value;
-
- private Exercise(String name, T value) {
- this.name = name;
- this.value = value;
- }
-
- public static Exercise of(String name, T value) {
- return new Exercise(name, value);
- }
-
- public String getName() {
- return this.name;
- }
-
- public T getValue() {
- return this.value;
- }
-
- @java.lang.Override
- public boolean equals(Object o) {
- if (o == this) return true;
- if (!(o instanceof ValueExample.Exercise)) return false;
- final Exercise> other = (Exercise>)o;
- final Object this$name = this.getName();
- final Object other$name = other.getName();
- if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
- final Object this$value = this.getValue();
- final Object other$value = other.getValue();
- if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false;
- return true;
- }
-
- @java.lang.Override
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- final Object $name = this.getName();
- result = result * PRIME + ($name == null ? 0 : $name.hashCode());
- final Object $value = this.getValue();
- result = result * PRIME + ($value == null ? 0 : $value.hashCode());
- return result;
- }
-
- @java.lang.Override
- public String toString() {
- return "ValueExample.Exercise(name=" + getName() + ", value=" + getValue() + ")";
- }
- }
-}
\ No newline at end of file
diff --git a/usage_examples/experimental/ValueExample_pre.jpage b/usage_examples/experimental/ValueExample_pre.jpage
deleted file mode 100644
index d9550c25..00000000
--- a/usage_examples/experimental/ValueExample_pre.jpage
+++ /dev/null
@@ -1,19 +0,0 @@
-import lombok.AccessLevel;
-import lombok.experimental.NonFinal;
-import lombok.experimental.Value;
-import lombok.experimental.Wither;
-import lombok.ToString;
-
-@Value public class ValueExample {
- String name;
- @Wither(AccessLevel.PACKAGE) @NonFinal int age;
- double score;
- protected String[] tags;
-
- @ToString(includeFieldNames=true)
- @Value(staticConstructor="of")
- public static class Exercise {
- String name;
- T value;
- }
-}
diff --git a/website/features/experimental/Wither.html b/website/features/experimental/Wither.html
index 9cbcd5ed..b334cd7c 100644
--- a/website/features/experimental/Wither.html
+++ b/website/features/experimental/Wither.html
@@ -46,6 +46,8 @@
a 'wither' is generated for each field (even non-final fields).
To put annotations on the generated method, you can use onMethod=@_({@AnnotationsHere})
; to put annotations on the only parameter of a generated wither method, you can use onParam=@_({@AnnotationsHere})
. Be careful though! This is an experimental feature. For more details see the documentation on the onX feature.
+
+ NEW in lombok v1.12.0: javadoc on the field will now be copied to generated withers. Normally, all text is copied, and @param
is moved to the wither, whilst @return
lines are stripped from the wither's javadoc. Moved means: Deleted from the field's javadoc. It is also possible to define unique text for the wither's javadoc. To do that, you create a 'section' named WITHER
. A section is a line in your javadoc containing 2 or more dashes, then the text 'WITHER', followed by 2 or more dashes, and nothing else on the line. If you use sections, @return
and @param
stripping / copying for that section is no longer done (move the @param
line into the section).
--
cgit