Browse Source

Remove support for generics nullability for now

See https://github.com/Kotlin/KEEP/issues/79
pull/1527/merge
Sebastien Deleuze 7 years ago
parent
commit
6c4a103f70
  1. 8
      spring-core/src/main/java/org/springframework/lang/NonNull.java
  2. 6
      spring-core/src/main/java/org/springframework/lang/NonNullApi.java
  3. 5
      spring-core/src/main/java/org/springframework/lang/NonNullFields.java
  4. 4
      spring-core/src/main/java/org/springframework/lang/Nullable.java
  5. 8
      src/docs/asciidoc/kotlin.adoc

8
spring-core/src/main/java/org/springframework/lang/NonNull.java

@ -30,15 +30,13 @@ import javax.annotation.meta.TypeQualifierNickname; @@ -30,15 +30,13 @@ import javax.annotation.meta.TypeQualifierNickname;
* Leverages JSR 305 meta-annotations to indicate nullability in Java to common tools with
* JSR 305 support and used by Kotlin to infer nullability of Spring API.
*
* <p>Should be used at generic type argument, parameter, return value, and field level.
* <p>Should be used at parameter, return value, and field level.
* Methods overrides should repeat parent {@code @NonNull} annotations unless they behave
* differently.
*
* <p>Use {@code @NonNullApi} (scope = parameters + return values) and/or {@code @NonNullFields}
* (scope = fields) to set the default behavior to non-nullable in order to avoid annotating
* your whole codebase with {@code @NonNull}. No default retricted to generic type argument
* is possible ({@code ElementType.TYPE_USE} scope is too wide) so each generic type argument
* needs to be annotated with @code @NonNull}.
* your whole codebase with {@code @NonNull}.
*
* @author Sebastien Deleuze
* @author Juergen Hoeller
@ -47,7 +45,7 @@ import javax.annotation.meta.TypeQualifierNickname; @@ -47,7 +45,7 @@ import javax.annotation.meta.TypeQualifierNickname;
* @see NonNullFields
* @see Nullable
*/
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE_USE, ElementType.FIELD})
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull

6
spring-core/src/main/java/org/springframework/lang/NonNullApi.java

@ -30,15 +30,9 @@ import javax.annotation.meta.TypeQualifierDefault; @@ -30,15 +30,9 @@ import javax.annotation.meta.TypeQualifierDefault;
* Leverages JSR 305 meta-annotations to indicate nullability in Java to common tools with
* JSR 305 support and used by Kotlin to infer nullability of Spring API.
*
*
* <p>Should be used at package level in association with {@link Nullable}
* annotations at parameter and return value level.
*
* <p>This annotation does not define nullability of generic type arguments, because
* {@code @TypeQualifierDefault(ElementType.TYPE_USE)} scope would be too broad.
* As a consequence, each API generic type argument should be annotated
* with {@link Nullable} or {@link NonNull} to specify their nullability.
*
* @author Sebastien Deleuze
* @author Juergen Hoeller
* @since 5.0

5
spring-core/src/main/java/org/springframework/lang/NonNullFields.java

@ -34,11 +34,6 @@ import javax.annotation.meta.TypeQualifierDefault; @@ -34,11 +34,6 @@ import javax.annotation.meta.TypeQualifierDefault;
* <p>Should be used at package level in association with {@link Nullable}
* annotations at field level.
*
* <p>This annotation does not define nullability of generic type arguments, because
* {@code @TypeQualifierDefault(ElementType.TYPE_USE)} scope would be too broad.
* As a consequence, each field generic type argument should be annotated
* with {@link Nullable} or {@link NonNull} to specify their nullability.
*
* @author Sebastien Deleuze
* @since 5.0
* @see NonNullFields

4
spring-core/src/main/java/org/springframework/lang/Nullable.java

@ -30,7 +30,7 @@ import javax.annotation.meta.When; @@ -30,7 +30,7 @@ import javax.annotation.meta.When;
* some circumstance. Leverages JSR 305 meta-annotations to indicate nullability in Java
* to common tools with JSR 305 support and used by Kotlin to infer nullability of Spring API.
*
* <p>Should be used at generic type argument, parameter, return value, and field level.
* <p>Should be used at parameter, return value, and field level.
* Methods overrides should repeat parent {@code @Nullable} annotations unless they behave
* differently.
*
@ -44,7 +44,7 @@ import javax.annotation.meta.When; @@ -44,7 +44,7 @@ import javax.annotation.meta.When;
* @see NonNullFields
* @see NonNull
*/
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE_USE, ElementType.FIELD})
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull(when = When.MAYBE)

8
src/docs/asciidoc/kotlin.adoc

@ -111,12 +111,8 @@ the default behavior in an upcoming release of Kotlin. @@ -111,12 +111,8 @@ the default behavior in an upcoming release of Kotlin.
[NOTE]
====
Make sure to https://github.com/sdeleuze/spring-kotlin-functional/blob/2d6ac07adfc2b8f25e91681dbb2b58a1c6cdf9a7/build.gradle.kts#L57[include JSR-305 JAR]
until Kotlin 1.1.5 is released (it will fix https://youtrack.jetbrains.com/issue/KT-19419[KT-19419]).
Support for generic type arguments, varargs and array elements is still work in progress,
see https://youtrack.jetbrains.com/issue/KT-19592[KT-19592] and
https://youtrack.jetbrains.com/issue/IDEA-153093[IDEA-153093] for up-to-date
Generic type arguments, varargs and array elements nullability are not yet supported,
see https://github.com/Kotlin/KEEP/issues/79[this dicussion] for up-to-date
informations.
====

Loading…
Cancel
Save