aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2015-10-05 21:58:00 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2015-10-05 21:58:00 +0200
commite94a5f9ee3e003c6b889168796bc010072177d14 (patch)
tree8ab3e6627b168738ae8a9626044379551ceebb45
parent264c66b53f29c49238ada2c4b93d91b0a5bc9b41 (diff)
downloadlombok-e94a5f9ee3e003c6b889168796bc010072177d14.tar.gz
lombok-e94a5f9ee3e003c6b889168796bc010072177d14.tar.bz2
lombok-e94a5f9ee3e003c6b889168796bc010072177d14.zip
[Fixes #807] The NonNull annotation can now be used documentary style on params of abstract methods. The warning has been eliminated.
-rw-r--r--doc/changelog.markdown1
-rw-r--r--src/core/lombok/eclipse/handlers/HandleNonNull.java2
-rw-r--r--src/core/lombok/javac/handlers/HandleNonNull.java2
-rw-r--r--test/transform/resource/after-delombok/NonNullOnParameterOfDefaultMethod.java9
-rw-r--r--test/transform/resource/after-ecj/NonNullOnParameterOfDefaultMethod.java10
-rw-r--r--test/transform/resource/before/NonNullOnParameterOfDefaultMethod.java6
-rw-r--r--test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages1
-rw-r--r--test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages1
-rw-r--r--test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages1
-rw-r--r--website/features/NonNull.html5
10 files changed, 32 insertions, 6 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index 0746459e..ba1ea4b5 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -3,6 +3,7 @@ Lombok Changelog
### v1.16.7 "Edgy Guinea Pig"
* BUGFIX: `@Value` and `@FieldDefaults` no longer make uninitialized static fields final. [Issue #928](https://github.com/rzwitserloot/lombok/issues/928).
+* ENHANCEMENT: Putting `@NonNull` on a parameter of an abstract method no longer generates a warning, to allow you to use this annotation to document intended behaviour [Issue #807](https://github.com/rzwitserloot/lombok/issues/807).
### v1.16.6 (August 18th, 2015)
* FEATURE: `@Helper` can be placed on method-local inner classes to make all methods in the class accessible to the rest of the method. [Full documentation](https://projectlombok.org/features/experimental/Helper.html).
diff --git a/src/core/lombok/eclipse/handlers/HandleNonNull.java b/src/core/lombok/eclipse/handlers/HandleNonNull.java
index d904de2f..d09993ed 100644
--- a/src/core/lombok/eclipse/handlers/HandleNonNull.java
+++ b/src/core/lombok/eclipse/handlers/HandleNonNull.java
@@ -91,7 +91,7 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> {
if (isGenerated(declaration)) return;
if (declaration.isAbstract()) {
- annotationNode.addWarning("@NonNull is meaningless on a parameter of an abstract method.");
+ // This used to be a warning, but as @NonNull also has a documentary purpose, better to not warn about this. Since 1.16.7
return;
}
diff --git a/src/core/lombok/javac/handlers/HandleNonNull.java b/src/core/lombok/javac/handlers/HandleNonNull.java
index cd8e3402..ea6b39da 100644
--- a/src/core/lombok/javac/handlers/HandleNonNull.java
+++ b/src/core/lombok/javac/handlers/HandleNonNull.java
@@ -85,7 +85,7 @@ public class HandleNonNull extends JavacAnnotationHandler<NonNull> {
}
if (declaration.body == null) {
- annotationNode.addWarning("@NonNull is meaningless on a parameter of an abstract method.");
+ // This used to be a warning, but as @NonNull also has a documentary purpose, better to not warn about this. Since 1.16.7
return;
}
diff --git a/test/transform/resource/after-delombok/NonNullOnParameterOfDefaultMethod.java b/test/transform/resource/after-delombok/NonNullOnParameterOfDefaultMethod.java
new file mode 100644
index 00000000..cffff320
--- /dev/null
+++ b/test/transform/resource/after-delombok/NonNullOnParameterOfDefaultMethod.java
@@ -0,0 +1,9 @@
+interface NonNullOnParameterOfDefaultMethod {
+ void test(@lombok.NonNull String arg);
+ default void test2(@lombok.NonNull String arg) {
+ if (arg == null) {
+ throw new java.lang.NullPointerException("arg");
+ }
+ System.out.println(arg);
+ }
+}
diff --git a/test/transform/resource/after-ecj/NonNullOnParameterOfDefaultMethod.java b/test/transform/resource/after-ecj/NonNullOnParameterOfDefaultMethod.java
new file mode 100644
index 00000000..85e99702
--- /dev/null
+++ b/test/transform/resource/after-ecj/NonNullOnParameterOfDefaultMethod.java
@@ -0,0 +1,10 @@
+interface NonNullOnParameterOfDefaultMethod {
+ void test(@lombok.NonNull String arg);
+ default void test2(@lombok.NonNull String arg) {
+ if ((arg == null))
+ {
+ throw new java.lang.NullPointerException("arg");
+ }
+ System.out.println(arg);
+ }
+}
diff --git a/test/transform/resource/before/NonNullOnParameterOfDefaultMethod.java b/test/transform/resource/before/NonNullOnParameterOfDefaultMethod.java
new file mode 100644
index 00000000..3b35e90e
--- /dev/null
+++ b/test/transform/resource/before/NonNullOnParameterOfDefaultMethod.java
@@ -0,0 +1,6 @@
+interface NonNullOnParameterOfDefaultMethod {
+ void test(@lombok.NonNull String arg);
+ default void test2(@lombok.NonNull String arg) {
+ System.out.println(arg);
+ }
+}
diff --git a/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages b/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages
deleted file mode 100644
index fd5bffd5..00000000
--- a/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages
+++ /dev/null
@@ -1 +0,0 @@
-6 @NonNull is meaningless on a parameter of an abstract method.
diff --git a/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages b/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages
deleted file mode 100644
index 8eb312ef..00000000
--- a/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages
+++ /dev/null
@@ -1 +0,0 @@
-6 @NonNull is meaningless on a parameter of an abstract method. \ No newline at end of file
diff --git a/test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages b/test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages
deleted file mode 100644
index 0d9fcfdc..00000000
--- a/test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages
+++ /dev/null
@@ -1 +0,0 @@
-9 @NonNull is meaningless on a parameter of an abstract method. \ No newline at end of file
diff --git a/website/features/NonNull.html b/website/features/NonNull.html
index d62441f4..50acf627 100644
--- a/website/features/NonNull.html
+++ b/website/features/NonNull.html
@@ -15,7 +15,7 @@
<div class="overview">
<h3>Overview</h3>
<p>
- <em>NEW in Lombok 0.11.10: </em>You can use <code>@NonNull</code> on the parameter of a method or constructor to have lombok generate a null-check statement for you.
+ <em>NEW in Lombok 0.11.10: </em>You can use <code>@NonNull</code> on the parameter of a method or constructor to have lombok generate a null-check statement for you.<br />
</p><p>
Lombok has always treated any annotation named <code>@NonNull</code> on a field as a signal to generate a null-check if lombok generates an entire method or constructor for you, via
for example <a href="Data.html"><code>@Data</code></a>. Now, however, using lombok's own <code>@lombok.NonNull</code> on a parameter results in the insertion of just the null-check
@@ -60,6 +60,9 @@
this feature only triggers on lombok's own <code>@NonNull</code> annotation from the <code>lombok</code> package.
</p><p>
A <code>@NonNull</code> on a primitive parameter results in a warning. No null-check will be generated.
+ </p><p>
+ A <code>@NonNull</code> on a parameter of an abstract method used to generate a warning; starting with version 1.16.8, this is no longer the case, to acknowledge the notion that <code>@NonNull</code> also has a
+ documentary role. For the same reason, you can annotate a method as <code>@NonNull</code>; this is allowed, generates no warning, and does not generate any code.
</p>
</div>
</div>