From 0d0aba6bef8d911482a0fb3caf601f3c57ac955a Mon Sep 17 00:00:00 2001 From: MoonFruit Date: Tue, 4 Mar 2025 18:37:00 +0800 Subject: [PATCH] Add jspecify Nonnull/Nullable annotations --- AUTHORS | 1 + src/core/lombok/ConfigurationKeys.java | 3 ++- src/core/lombok/core/configuration/NullAnnotationLibrary.java | 3 ++- website/templates/features/configuration.html | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index ebbc5b37..c7324be9 100755 --- a/AUTHORS +++ b/AUTHORS @@ -62,5 +62,6 @@ Till Brychcy Victor Williams Stafusa da Silva Yonatan Sherwin Yun Zhi Lin +MoonFruit By adding your name to this list, you grant full and irrevocable copyright and patent indemnity to Project Lombok and all use of Project Lombok in relation to all commits you add to Project Lombok, and you certify that you have the right to do so. diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index b19dccfc..2460edd3 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -106,7 +106,7 @@ public class ConfigurationKeys { public static final ConfigurationKey ADD_SUPPRESSWARNINGS_ANNOTATIONS = new ConfigurationKey("lombok.addSuppressWarnings", "Generate @java.lang.SuppressWarnings(\"all\") on all generated code (default: true).") {}; /** - * lombok configuration: {@code lombok.addNullAnnotations = }one of: [{@code none}, {@code javax}, {@code eclipse}, {@code jetbrains}, {@code netbeans}, {@code androidx}, {@code android.support}, {@code checkerframework}, {@code findbugs}, {@code spring}, {@code JML}, or a custom set of fully qualified annotation types]. + * lombok configuration: {@code lombok.addNullAnnotations = }one of: [{@code none}, {@code javax}, {@code eclipse}, {@code jetbrains}, {@code netbeans}, {@code androidx}, {@code android.support}, {@code checkerframework}, {@code findbugs}, {@code spring}, {@code JML}, {@code jspecify} or a custom set of fully qualified annotation types]. * * Lombok generally copies relevant nullity annotations from your source code to the right places. However, sometimes lombok generates code where the nullability of some node is not dependent on something in your source code. You can configure lombok to add an appropriate nullity annotation in this case.
    *
  • {@code none} (the default) - no annotations are added.
  • @@ -121,6 +121,7 @@ public class ConfigurationKeys { *
  • {@code findbugs} - The annotations {@code edu.umd.cs.findbugs.annotations.NonNull} and {@code edu.umd.cs.findbugs.annotations.Nullable} are used.
  • *
  • {@code spring} - The annotations {@code org.springframework.lang.NonNull} and {@code org.springframework.lang.Nullable} are used.
  • *
  • {@code jml} - The annotations {@code org.jmlspecs.annotation.NonNull} and {@code org.jmlspecs.annotation.Nullable} are used.
  • + *
  • {@code jspecify} - The annotations {@code org.jspecify.annotations.NonNull} and {@code org.jspecify.annotations.Nullable} are used.
  • *
  • CUSTOM:fully.qualified.nonnull.annotation:fully.qualified.nullable.annotation to configure your own types; the nullable annotation (and the colon) are optional.
  • *
*

diff --git a/src/core/lombok/core/configuration/NullAnnotationLibrary.java b/src/core/lombok/core/configuration/NullAnnotationLibrary.java index e1d31004..1187685f 100644 --- a/src/core/lombok/core/configuration/NullAnnotationLibrary.java +++ b/src/core/lombok/core/configuration/NullAnnotationLibrary.java @@ -73,7 +73,8 @@ public final class NullAnnotationLibrary implements ConfigurationValueType { public static final NullAnnotationLibrary FINDBUGS = new NullAnnotationLibrary("findbugs", "edu.umd.cs.findbugs.annotations.NonNull", "edu.umd.cs.findbugs.annotations.Nullable", false); public static final NullAnnotationLibrary SPRING = new NullAnnotationLibrary("spring", "org.springframework.lang.NonNull", "org.springframework.lang.Nullable", false); public static final NullAnnotationLibrary JML = new NullAnnotationLibrary("jml", "org.jmlspecs.annotation.NonNull", "org.jmlspecs.annotation.Nullable", false); - + public static final NullAnnotationLibrary JSPECIFY = new NullAnnotationLibrary("jspecify", "org.jspecify.annotations.NonNull", "org.jspecify.annotations.Nullable", true); + private static final List ALL_AVAILABLE; private static final String EXAMPLE_VALUE; diff --git a/website/templates/features/configuration.html b/website/templates/features/configuration.html index c3c39835..b33eef40 100644 --- a/website/templates/features/configuration.html +++ b/website/templates/features/configuration.html @@ -87,7 +87,7 @@

  1. lombok.addNullAnnotations = <flavor>
- Many flavors are available: javax (=JSR305; not recommended), jakarta, eclipse, jetbrains, netbeans, androidx, android.support (deprecated within android), checkerframework (recommended), findbugs, spring, jml, or define your own via CUSTOM:fully.qualified.NonNullAnnotation:fully.qualified.NullableAnnotation; if your nullity annotation is solely of the type use style (it annotates types, such as eclipse's and checkerframework's offerings, versus annotating methods and parameters), the format is CUSTOM:TYPE_USE:nonnullanno:nullableanno.
+ Many flavors are available: javax (=JSR305; not recommended), jakarta, eclipse, jetbrains, netbeans, androidx, android.support (deprecated within android), checkerframework (recommended), findbugs, spring, jml, jspecify, or define your own via CUSTOM:fully.qualified.NonNullAnnotation:fully.qualified.NullableAnnotation; if your nullity annotation is solely of the type use style (it annotates types, such as eclipse's and checkerframework's offerings, versus annotating methods and parameters), the format is CUSTOM:TYPE_USE:nonnullanno:nullableanno.
This feature was added in lombok v1.18.12.

Lombok can be configured to add @lombok.Generated annotations to all generated nodes where possible; useful for JaCoCo (which has built in support),