37
37
import org .jspecify .annotations .Nullable ;
38
38
39
39
/**
40
- * Constants that indicate the nullness, as well as related utility methods.
40
+ * Constants that indicate nullness, as well as related utility methods.
41
41
*
42
- * <p>The nullness applies to a type usage, a field, a method return type or a parameter.
43
- * <a href="https://jspecify.dev/docs/user-guide/">JSpecify annotations</a> are fully supported, as well as
44
- * <a href="https://kotlinlang.org/docs/null-safety.html">Kotlin null safety</a>, {@code @Nullable} annotations
45
- * regardless of their package and Java primitive types.
42
+ * <p>Nullness applies to type usage, a field, a method return type, or a parameter.
43
+ * <a href="https://jspecify.dev/docs/user-guide/">JSpecify annotations</a> are
44
+ * fully supported, as well as
45
+ * <a href="https://kotlinlang.org/docs/null-safety.html">Kotlin null safety</a>,
46
+ * {@code @Nullable} annotations regardless of their package, and Java primitive
47
+ * types.
46
48
*
47
- * <p>JSR-305 annotations as well as Spring ones in the {@code org.springframework.lang} packages such as
48
- * {@code @NonNullApi}, {@code @NonNullFields} and {@code @NonNull} are not supported by this API, except
49
- * {@code @Nullable} which is supported via the package-less check. Migrating to JSpecify is recommended.
49
+ * <p>JSR-305 annotations as well as Spring null safety annotations in the
50
+ * {@code org.springframework.lang} package such as {@code @NonNullApi},
51
+ * {@code @NonNullFields}, and {@code @NonNull} are not supported by this API.
52
+ * However, {@code @Nullable} is supported via the package-less check. Migrating
53
+ * to JSpecify is recommended.
50
54
*
51
55
* @author Sebastien Deleuze
52
56
* @since 7.0
53
57
*/
54
58
public enum Nullness {
55
59
56
60
/**
57
- * Unspecified nullness (Java default for non-primitive types and JSpecify {@code @NullUnmarked} code).
61
+ * Unspecified nullness (Java default for non-primitive types and JSpecify
62
+ * {@code @NullUnmarked} code).
58
63
*/
59
64
UNSPECIFIED ,
60
65
@@ -70,7 +75,7 @@ public enum Nullness {
70
75
71
76
72
77
/**
73
- * Return the nullness of the given method return type.
78
+ * Return the nullness of the return type for the given method .
74
79
* @param method the source for the method return type
75
80
* @return the corresponding nullness
76
81
*/
@@ -123,7 +128,8 @@ public static Nullness forField(Field field) {
123
128
}
124
129
125
130
126
- // Check method and parameter level @Nullable annotations regardless of the package (including Spring and JSR 305 annotations)
131
+ // Check method and parameter level @Nullable annotations regardless of the package
132
+ // (including Spring and JSR 305 annotations)
127
133
private static boolean hasNullableAnnotation (AnnotatedElement element ) {
128
134
for (Annotation annotation : element .getDeclaredAnnotations ()) {
129
135
if ("Nullable" .equals (annotation .annotationType ().getSimpleName ())) {
@@ -133,7 +139,9 @@ private static boolean hasNullableAnnotation(AnnotatedElement element) {
133
139
return false ;
134
140
}
135
141
136
- private static Nullness jSpecifyNullness (AnnotatedElement annotatedElement , Class <?> declaringClass , AnnotatedType annotatedType ) {
142
+ private static Nullness jSpecifyNullness (
143
+ AnnotatedElement annotatedElement , Class <?> declaringClass , AnnotatedType annotatedType ) {
144
+
137
145
if (annotatedType .getType () instanceof Class <?> clazz && clazz .isPrimitive ()) {
138
146
return (clazz != void .class ? Nullness .NON_NULL : Nullness .UNSPECIFIED );
139
147
}
@@ -171,7 +179,6 @@ else if (annotatedElement.isAnnotationPresent(NullUnmarked.class)) {
171
179
*/
172
180
private static class KotlinDelegate {
173
181
174
-
175
182
public static Nullness forMethodReturnType (Method method ) {
176
183
KFunction <?> function = ReflectJvmMapping .getKotlinFunction (method );
177
184
if (function != null && function .getReturnType ().isMarkedNullable ()) {
0 commit comments